Tìm kiếm hỗ trợ

Tránh các lừa đảo về hỗ trợ. Chúng tôi sẽ không bao giờ yêu cầu bạn gọi hoặc nhắn tin đến số điện thoại hoặc chia sẻ thông tin cá nhân. Vui lòng báo cáo hoạt động đáng ngờ bằng cách sử dụng tùy chọn "Báo cáo lạm dụng".

Tìm hiểu thêm

Javascript smooth scrolling doesn't work in Firefox

  • 1 trả lời
  • 1 gặp vấn đề này
  • 7 lượt xem
  • Trả lời mới nhất được viết bởi 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.

Được chỉnh sửa bởi cor-el vào

Tất cả các câu trả lời (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.