Wednesday, 18 September 2013

Is it possible to increase the speed of the .css method on the .scroll event?

Is it possible to increase the speed of the .css method on the .scroll event?

This is my code:
$( window ).scroll( function () {
scrollBG( '#about' );
}
function scrollBG( e ) {
bg_position = $( document ).scrollTop() / 2;
$( e ).css( 'background-position-y', bg_position );
}
What it does is scroll the background of an element as the user scrolls.
This works fine, the only issue is when using the mousewheel to scroll,
the css take a few milliseconds to catch up (since the mousewheel will
move like 100px at a time).
Is there way to make the css change happen instantaneously? Perhaps native
JavaScript is faster?
I've noticed this plugin does not have the issue I'm facing, but I don't
want to use it as it seems overkill for my needs:
http://johnpolacek.github.io/superscrollorama/

No comments:

Post a Comment