Created
February 18, 2017 06:40
-
-
Save Caldis/e4d283e177034925507b58cb6ac33b0e to your computer and use it in GitHub Desktop.
jQueryClassAnim.js
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function addAnimateClass(target, animClass, interval, duration, removeAfterAnim, callback) { | |
// 清掉类名和定时器 | |
target.each(function(){ | |
$(this).removeClass(animClass); | |
}); | |
// 添加动画类 | |
target.each(function(i){ | |
var t = $(this); | |
setTimeout(function() { | |
t.addClass(animClass); | |
}, (i+1) * interval); | |
}); | |
// 清除已添加的类 | |
if(removeAfterAnim) { | |
setTimeout(function () { | |
target.each(function () { | |
$(this).removeClass(animClass); | |
}); | |
}, target.length * (interval) + duration); | |
} | |
// 执行回调函数 | |
if(typeof callback == "function") { | |
clearTimeout(target[0].callBackTimeOut); | |
target[0].callBackTimeOut = setTimeout(function(){ | |
callback(); | |
}, target.length*interval+duration*0.8); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment