javascript - jQuery animate triggers .complete callback 5 times -
can't catch mistake.. please figure out why callback of animate triggers several times.
code below scroll textblock top bottom. "step" of animate moves custom scrollbar...
currenttext.stop().animate({ top: "-"+textheight+"px"}, { duration: durationofautoscroll, step: function(currenttop) { var positiony = currenttop; if (positiony < curstate.maskheight - curstate.textheight) positiony = curstate.maskheight - curstate.textheight; if (positiony > 0) positiony = 0; var scrollposition = -positiony * curstate.scrollheight / (curstate.textheight - curstate.maskheight); curstate.scrollertop = scrollposition; $(".news-text .scroll-bar .scroller").css("top", scrollposition); }, complete: function() { //jquery.dequeue(currenttext); currenttext.attr("data-state", 0); onendscroll(); } } );
this means collection (currenttext) has 5 elements, callback fired once each element, expected behavior.
if that's not want, can create promise object , use done method:
currenttext.stop().animate({ top: "..." }, { duration: '...', step: function () { // ... }, }).promise().done(function () { // done });
Comments
Post a Comment