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),

  1. to use either css method rather animate
  2. executing stop() before animating should help.
  3. check existing color value before executing animate method

to know more stop() in jquery.


Comments

Popular posts from this blog

c++ - Difference between pre and post decrement in recursive function argument -

php - Nothing but 'run(); ' when browsing to my local project, how do I fix this? -

php - How can I echo out this array? -