Търсене в помощните статии

Избягвайте измамите при поддръжката. Никога няма да ви помолим да се обадите или изпратите SMS на телефонен номер или да споделите лична информация. Моля, докладвайте подозрителна активност на "Докладване за злоупотреба".

Learn More

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.