jQuery easing animation of window scroll in Firefox (bug or my bad?)
Asked Answered
E

5

5

THE EXAMPLE
First and foremost, here's my code and problem:
http://www.nathanstpierre.com/MBX/showoff.html

THE ISSUE
So what I'm seeing is when you click the buttons on the left, the window scrolls to the appropriate heading. In every browser but Firefox (including... IE gasp) this is very smooth. However, if you reduce the height of the window, it becomes smooth on all computers. I've already tried this on multiple computers and on IE 7-8, Google Chrome, Safari, and Firefox 3.5. I've eliminated every bit of graphic and color on the page, so those aren't the issue. I've gotten rid of the sidebar that follows you, that's not it.

THE THEORY
I think that the jQuery easing plugin calculates the distance that you're needing to go, and then divides up the number of pixels it needs to move per unit of duration specified (say 300 pixels over 30 milliseconds, so 10px/ms). Every other browser seems to be able to make this a smooth transition, but maybe the granularity provided by the window scroll event is not compressed enough for Firefox to make this appear smooth? Or maybe I'm using the wrong easing plugin, or the wrong settings.

THE CODE

$("#sidenav a").click(function () {
        $("#sidenav a").animate({'color':'#6d6d6d'},{"duration":400});
        $(this).animate({"color":"#fff"},{"duration":400});
        clicktarget=$(this).attr("href");
        $("html, body").animate({scrollTop: $(clicktarget).offset().top},{"duration":300,"easing":"easeout"});
        return false;
      });

THE LOGIC

Add an event listener to each a tag on the sidenav onClick. This will get the offset().top of the element in the document with the same ID as the href attribute of that link, and then animate from the current scrollTop to the offset().top of that element. The logic is sound, and works smoothly in every browser EXCEPT Firefox... as far as I can tell.

THE PLEA

What am I doing wrong? Is this a bug?

Thanks!

THE UPDATE

Well I can't in good conscience choose any of the answers presented here, as none of them have actually given a resolution to the issue, so if you're following this pick your favorite and the bounty will go to the one with the highest votes.

The issue appears to be the way that Firefox a) renders transparency and b) deals with scrolling events. Potentially with enough processor power this is a non-issue, but what makes me sad is that IE (of all browsers) is capable of rendering this fine on inferior hardware. I'll approach Mozilla with the issue and see if they've got anything to say about it.

For extra edification, the following are provided at no charge:

With Transparency
Without Transparency

EDIT: So the question has been answered, but now I can't choose it. Anyone know what's up with that?

FINAL UPDATE Enough time had passed that they let me have the bounty back, so I chose the answer that was correct. It looks like box-shadow and a few other effects cause some scrolling issues in firefox because of the way they render. FF 4.0 + handles this better, but some computers still have issues. This is a great heads up for people implementing CSS3: test the interaction on all browsers and see if the performance costs are justifiable.

Engraft answered 19/1, 2010 at 22:29 Comment(9)
Works fine on Firefox 3.6 RC2 Mac OS XKamkama
@Paolo : Hmm maybe it was fixed in 3.6, I'll check that next. Thanks for the heads up.Engraft
@Paolo: Nope, looks like it's still an issue. To see an example of what I mean, shrink the window down to about 400 pixels tall, and then hit the buttons to see a comparison. It's not really a big deal but I'm nitpicky and I think I've discovered a potential bug either with the way jquery animates or the way firefox understand that animation.Engraft
@NateDSaint: I can't see any difference between Safari 4.04 and Firefox 3.6 RC2. I made this screen recording where I'm using both: vimeo.com/8862134Kamkama
@Paolo : You know what? I didn't have the RC, I'm on an old Beta. I'll download RC2 and check it out, they might have fixed it. Thanks for the video!Engraft
Okay so if you check out www.nathanstpierre.com/MBX/transtest.php and then compare it to www.nathanstpierre.com/MBX/transtest.php?transparent=no you'll see the page with and without transparency. There's a slight pickup in framerate on the scroll but not much. I've downloaded 3.6 RC2 and it looks the same. I think Paolo's test is a little confusing because it's not the full width of the screen on either browser. I think it's either a bug or an issue with jQuery's easing methods, so I'll just go with it for now and come back to check on it later.Engraft
Works fine by me on Firefox 3.6 on Windows 7.Rajah
This may not be significant, but on every window.scroll event you are attempting to fade your "top" link either in or out. When you click one of your links or otherwise scroll the page Firefox will fire multiple window.scroll events. If the link is currently visible then I don't think jQuery will queue additional fade up animations, but when it's hidden you are ending up with multiple fade in animations queued.Literatim
That's a really good point, Richard, and thanks for catching it! Unfortunately the top link was added recently, after all this was discovered. But I'll make sure to optimize that as I'm sure it's not helping at all.Engraft
L
4

The poor performance seems to be caused by the -moz-box-shadow property, if you remove any declarations of this property (or disable them with Firebug) the scrolling animation is much smoother.

Literatim answered 6/2, 2010 at 2:7 Comment(3)
this fixed it! Although now it looks like I have another problem, it won't let me select this as the answer.Engraft
Seems like you answered this right after the bounty expired so I can't pick you. : ( But this is the right answer, so if anyone comes to the same issue, this is the resolution as of now. Mozilla is aware that their implementation of box-shadow is a resource hog and is working to optimize it.Engraft
Looks like they changed the rules, so I was able to accept this answer. huzzah!Engraft
Y
2

Please try jQuery 1.4. That seems the be much faster, then jQuery 1.3.2.

If you need to debug these kind of things, put the uncompressed js files in your code and use Firebug with it's profile, to profile the functions.

Yogini answered 3/2, 2010 at 19:12 Comment(1)
Those are all awesome points, and I kept assuming it was Firefox, but at the very least I can try to optimize everything to see if I can minimize the frame jerk. Thanks for the heads up!Engraft
H
1

You page is a bit heavy with the two backgrounds (one being a transparent .png ..)

The issue is with firefox and/or you machine handling the animation. Check the smooth scrolling option of Firefox ( Tools -> Options -> Advanced -> General -> Use Smooth Scrolling ). It might be the reason if it is checked off...

Hypothetical answered 19/1, 2010 at 22:42 Comment(3)
1) I realize the backgrounds are potentially not optimized, but I've turned them both off and the issue remains. I can provide an example if necessary. 2) I've turned it on, and it's still doing it. Do you not see the difference in animation between firefox and other browsers on your computer? Try loading it in another browser (IE, Chrome, Safari) and see the difference.Engraft
I can see the difference ... but my firefox is very heavy anyway .. so i think it is a firefox thing .. not something you do .. Did you try the smooth scrolling option of firefox ?Hypothetical
Yeah, you can also get there by going to about:config and then search for smoothscroll in the filter and check it there. At first I thought it was an optimization problem but I opened the site on a netbook (atom powered, running ubuntu netbook remix), and chrome has no drop in framerate, even though this thing has no more than a gig of ram and a slow processor. You load it in FF, however, and there's some jumping, but you resize the window and it's not so bad. I can't figure out if it's a math thing with firefox or just that the way firefox scrolls is a little more intensiveEngraft
T
0

whenever i have attempted a similar effect i have used ScrollTo. maybe that will help

ScrollTo Plugin

Trooper answered 1/2, 2010 at 11:12 Comment(1)
I've tried using this as well, and it actually looks like it might be better for choosing an appropriate easing, but the issue with Firefox appears to still be present as it uses the same core JS functionality.Engraft
C
0

I've had the same problem with FF 3.5 - definitely looks like a rendering problem. If you try it new 3.6 it will be probably ok.

I was having issues with doherty's coda slider 2.0 btw.

Regards

Andrej

Callao answered 8/2, 2010 at 11:44 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.