1

Is there any way to keep this simple JQuery animation from flashing? http://jsfiddle.net/v3DVf/6/

4
  • what do you mean by flashing? it doesn't flash for me Commented Mar 23, 2012 at 18:43
  • I suppose it's browser dependent. I'm running Chrome and it flashes pretty badly when if I scroll too quickly... Commented Mar 23, 2012 at 18:45
  • I just tried IE, which is really bad... Commented Mar 23, 2012 at 18:48
  • if you increase the top: (300 - (1.5 * $(window).scrollTop())) 0.5 to 1.5 its better
    – uday
    Commented Mar 23, 2012 at 18:52

1 Answer 1

4

It's probably because you're scrolling too fast for jQuery to calculate everything. This seems to help:

$(window).scroll(function() {
    var scrollTop = $(window).scrollTop();
    $('#left').stop().animate({
        top: (300 - (0.5 * scrollTop))
    }, 350);
    $('#right').stop().animate({
        top: (300 - (0.2 * scrollTop))
    }, 350);
});​

That's caching the scrollTop value rather than recalculating, and omitting the (true, true) from the stop function.

EDIT: Also, get rid of the #container css call, just make it position: fixed.

1
  • Yep. Between using a variable and setting #container to fixed, it seems that the flashing issue is solved. Thanks! jsfiddle.net/v3DVf/10 Commented Mar 23, 2012 at 19:05

Not the answer you're looking for? Browse other questions tagged or ask your own question.