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

javascript - three.js lot of meshes optimization -

smartface.io - Proper way to change color scheme for whole application -

Email notification in google apps script -