jquery - function being executed multiple times on page scrolling -
need help guys, so, have next code, recognize if user scroll downwards or up, , after scroll editable div downwards or up. i'm animating editable div show , show off, when scroll page executing function lot of times, , hampering animation causing delay. how function executed 1 time when scrolling occurs?
var position = $(window).scrolltop(); $(window).scroll(function() { var scroll = $(window).scrolltop(); if(scroll > position) { $("#textarea").animate({'top': '-75' + 'px'}, 500); } else { $("#textarea").addclass('fixed').animate({'top': '75' + 'px'}, 500); }; position = scroll; });
here fiddle: http://jsfiddle.net/s92e88le/
make work that:
var position = $(window).scrolltop(); $(window).scroll(function() { var scroll = $(window).scrolltop(); var isworking = 0; if(scroll > position) { $("#textarea").animate({'top': '-25' + 'px'}, 70); } else { if(isworking == 0) { isworking = 1; $("#textarea").addclass('fixed').animate({ 'top': '75' + 'px'}, 70, function() { isworking = 0; }); } }; position = scroll; });
jquery jquery-animate
No comments:
Post a Comment