javascript - JQuery Offset Script -
i creating navigation menu website. when user scrolls past point 497px needs change colour. have wrote script:
$(document).ready(function(){ function checkoffset() { var offset = $(document).scrolltop(); console.log(offset); if(offset > 497){ $("#fixedbar").animate({backgroundcolor: '#1b1b1b'}, 1000); $("#fixedbar nav a").animate({color: '#fff'}, 1000); }else{ $("#fixedbar").animate({backgroundcolor: '#fff'}, 1000); $("nav a").animate({color: '#1b1b1b'}, 1000); } } $(window).scroll(function() { checkoffset(); }); });
if refresh page , past point indeed changes, if scroll past point doesn't change. how can fix this?
your script works.
but since animating on every scroll. there chance of having consecutive animation cycles.
possible solutions (any 1 of these points),
- to use either
css
method ratheranimate
- executing
stop()
before animating should help. - check existing color value before executing
animate
method
to know more stop() in jquery.
Comments
Post a Comment