为提升您的使用体验,本站正在维护,部分功能暂时无法使用。如果本站文章无法解决您的问题,您想要向社区提问的话,请到 Twitter 上的 @FirefoxSupport 或 Reddit 上的 /r/firefox 提问,我们的支持社区将会很快回复您的疑问。

搜索 | 用户支持

防范以用户支持为名的诈骗。我们绝对不会要求您拨打电话或发送短信,及提供任何个人信息。请使用“举报滥用”选项报告涉及违规的行为。

详细了解

Javascript smooth scrolling doesn't work in Firefox

  • 1 个回答
  • 1 人有此问题
  • 7 次查看
  • 最后回复者为 Junk_Mail

more options

My issue is with website JavaScript code working on every browser but Firefox. I have a button at the bottom of my forum page to return the user to the top. It is enabled with smooth scroll and uses only a small bit of JavaScript, not Jquery. In every other browser, the page slides smoothly back up to the top. In Firefox, it jumps up abruptly; no scroll. While typing this, I don't see any options for enclosing the code in tags, so I'll try to place it here as is, and perhaps you can advise as to why Firefox won't play nice with the code?

<script>
(function(){
  gotop.addEventListener("click",scrollWindow);
  function scrollWindow(){  
 var speed = 1;
 var start = document.body.scrollTop;
 (function doit(){ 
      window.scrollTo(0, document.body.scrollTop - speed);
      if(document.body.scrollTop > start/2){
   speed = speed * 1.02;
          setTimeout(doit,0);  
  }else{
   if(speed / 1.02 > 1 && document.body.scrollTop > 0)speed = speed / 1.01;
          if(document.body.scrollTop > 0)setTimeout(doit,0);   
  }
 })();
 };
})();
</script>

I only have Ad Blocker Plus and Ghostery installed but this has been happening ever since I installed FF with no add-ons. It's FireFox 47.0 (Mac).

Thank you for any help.

My issue is with website JavaScript code working on every browser but Firefox. I have a button at the bottom of my forum page to return the user to the top. It is enabled with smooth scroll and uses only a small bit of JavaScript, not Jquery. In every other browser, the page slides smoothly back up to the top. In Firefox, it jumps up abruptly; no scroll. While typing this, I don't see any options for enclosing the code in tags, so I'll try to place it here as is, and perhaps you can advise as to why Firefox won't play nice with the code? <pre><nowiki> <script> (function(){ gotop.addEventListener("click",scrollWindow); function scrollWindow(){ var speed = 1; var start = document.body.scrollTop; (function doit(){ window.scrollTo(0, document.body.scrollTop - speed); if(document.body.scrollTop > start/2){ speed = speed * 1.02; setTimeout(doit,0); }else{ if(speed / 1.02 > 1 && document.body.scrollTop > 0)speed = speed / 1.01; if(document.body.scrollTop > 0)setTimeout(doit,0); } })(); }; })(); </script></nowiki></pre> I only have Ad Blocker Plus and Ghostery installed but this has been happening ever since I installed FF with no add-ons. It's FireFox 47.0 (Mac). Thank you for any help.

由cor-el于修改

所有回复 (1)

more options

I do see this error in the console:

ReferenceError: scrollWindow is not defined onclick()

I'm not sure how to fix that, if that's the issue, since any fix I guess at might affect the function in other browsers.