1
有许多问题关于阻止用户启动(即鼠标,触摸,键盘)通过JavaScript滚动。在这种情况下,我在CMS中创建了一个组件,该组件需要阻止另一个CMS组件滚动到视图中。我无法访问其他CMS组件的代码(这也是严重混淆)。防止JavaScript启动滚动
我曾尝试禁用迫使下面的代码滚动的典型方式,但其他CMS仍然滚动到视图中,第二个或两个以下代码后运行:
Element.prototype.scrollIntoView = function(alignWithTop){
console.log("******** scrollIntoView: " + this.getAttribute("id"));
};
Element.prototype.scrollIntoViewIfNeeded = function(alignWithTop){
console.log("******** scrollIntoViewIfNeeded: " + this.getAttribute("id"));
};
Element.prototype.scrollByLines = function(){
console.log("******** scrollByLines: " + this.getAttribute("id"));
};
Element.prototype.scrollByPages = function(){
console.log("******** scrollByPages: " + this.getAttribute("id"));
};
Element.prototype.focus = function(){
console.log("******** focus: " + this.getAttribute("id"));
};
window.scroll = function(xpos,ypos){
console.log("******** scroll: " + xpos+","+ypos);
}
window.scrollTo = function(xpos,ypos){
console.log("******** scrollTo: " + xpos+","+ypos);
}
window.scrollBy = function(xpos,ypos){
console.log("******** scrollBy: " + xpos+","+ypos);
}
jQuery.fn.scrollTop = function(){
console.log("!!!!!!!! scrollTop");
};
jQuery.fn.animate = function(){
console.log("!!!!!!!! animate");
};
jQuery.fn.click = function(){
console.log("!!!!!!!! click");
};
我可以设置window.onscroll
给力在一段时间内致电window.scrollTo(0,0)
,但这看起来并不令人满意,因为它看起来很刺眼,并且阻止了用户启动的滚动,我不想阻止它。
是否有其他方式的JavaScript(或jQuery)可以强制上述代码中缺少的滚动?
“滚动自己进入视图“ - 它是一个像淡入或类似的动画效果? – Vandesh
尝试返回false时,你认为它不应该滚动。 –
通过“自动滚动到视图中”我的意思是我的组件应该位于页面的顶部,下面提供了CMS提供的组件,名义上滚动页面的底部。但是当它加载时,CMS提供的组件会滚动到视图中。 –