Skip to content
This repository has been archived by the owner on Apr 28, 2020. It is now read-only.

Infinite loop FireFox when scrolling to top #13

Closed
willemliu opened this issue Dec 9, 2013 · 6 comments
Closed

Infinite loop FireFox when scrolling to top #13

willemliu opened this issue Dec 9, 2013 · 6 comments
Labels

Comments

@willemliu
Copy link

Hi,

I've encountered a problem in FireFox caused by a line of code. Line 86 in smooth-scroll.js present in commit: ad413a4 and probably some earlier commits as well.

The following IF-construction causes an infinite loop if you placed an anchor at the top of the page and you want to scroll to that anchor.

if ( travelled <= (endLocation(anchor) || 0) )

When looking into that if statement it's actually expected behaviour for it to cause an infinite loop. ((endLocation(anchor) || 0)) will actually be "false" when the anchor is at position 0 or smaller. So the body of the IF statement will only be executed when "travelled" is smaller or equals "false" which most of the time is never.
And as a result of the use of easing functions "travelled" will most likely never be exactly 0.

You can replace that with the following line to fix the bug.

if ( travelled <= (endLocation(anchor)) || travelled <= 0 )

Regards,

Willem

@cferdinandi
Copy link
Owner

@willemliu - Is there a way for me to test this? I've used it to successfully scroll to the top of the page before. If there were an infinite loop, wouldn't it either:

  1. Not scroll, or
  2. Stick at the top and not allow you to do anything else?

I've not encountered either of those.

@willemliu
Copy link
Author

I had this problem on my not yet complete website. My site using the Zurb Foundation responsive framework. So it's hard to pinpoint what combination of code would exactly cause the bug to appear.
What happens is what you mention at point 2. The site will relentlessly keep scrolling to the top. So I can't scroll down anymore.
I've been tracing the distance parameter and it becomes a value smaller than 0. From what I can see is that it happens when distance is 0 or smaller. And it only happens in FireFox. Other browsers seem to break out of the infinite loop.

@willemliu
Copy link
Author

I'll try to recreate the problem with a simple page tomorrow.

@cferdinandi
Copy link
Owner

@willemliu - If the code you provided solves the problem for you, no need. I'll make the updates and test later. Thanks!

@willemliu
Copy link
Author

Yes,

The line of code fixes the bug. Thanks!

Regards,

Willem

@cferdinandi
Copy link
Owner

Added in version 2.9. Thanks for the bug fix @willemliu!

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Projects
None yet
Development

No branches or pull requests

2 participants