防止javascript启动的滚动

防止javascript启动的滚动,javascript,jquery,scroll,Javascript,Jquery,Scroll,关于防止用户通过javascript启动(即鼠标、触摸、键盘)滚动,存在许多问题。在本例中,我正在CMS中创建一个组件,该组件需要阻止另一个CMS组件将自身滚动到视图中。我无法访问其他CMS组件的代码(该代码也被严重混淆) 我已经尝试过使用以下代码禁用强制滚动的典型方式,但在以下代码运行一两秒钟后,其他CMS仍会滚动到视图中: Element.prototype.scrollIntoView = function(alignWithTop){ console.log("*******

关于防止用户通过javascript启动(即鼠标、触摸、键盘)滚动,存在许多问题。在本例中,我正在CMS中创建一个组件,该组件需要阻止另一个CMS组件将自身滚动到视图中。我无法访问其他CMS组件的代码(该代码也被严重混淆)

我已经尝试过使用以下代码禁用强制滚动的典型方式,但在以下代码运行一两秒钟后,其他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)是否有其他方法可以强制执行我在上述代码中缺少的滚动?

因此这应该是显而易见的,但CMS调用的函数是
HTMLElementObject.focus()
,因此以下是我在页面加载和设置期间用于停止不需要的滚动的代码:

// Stop the page from jumping around for a little while
var oldFocus = Element.prototype.focus;
Element.prototype.focus = function(){};
setTimeout(
  function(){
    Element.prototype.focus = oldFocus;
  },5000);

“将自身滚动到视图中”-这是一种动画效果,如淡入淡入还是其他什么?如果您认为它不应该滚动,请尝试返回false。所谓“将自身滚动到视图中”,我的意思是我的组件应该位于页面顶部,下面是CMS提供的组件,名义上从页面底部滚动。但当它加载时,CMS提供的组件会向上滚动到视图中。