views:

1309

answers:

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?

+1  A: 

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...

Gaby
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.
NateDSaint
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 ?
Gaby
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 intensive
NateDSaint
A: 

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

ScrollTo Plugin

mroggle
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.
NateDSaint
+2  A: 

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.

Michiel
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!
NateDSaint
+2  A: 

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.

Richard M
this fixed it! Although now it looks like I have another problem, it won't let me select this as the answer.
NateDSaint
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.
NateDSaint
Looks like they changed the rules, so I was able to accept this answer. huzzah!
NateDSaint
A: 

Hi there,

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

Obrazy