Skip to content

Instantly share code, notes, and snippets.

@Caldis
Created February 18, 2017 06:40
Show Gist options
  • Save Caldis/e4d283e177034925507b58cb6ac33b0e to your computer and use it in GitHub Desktop.
Save Caldis/e4d283e177034925507b58cb6ac33b0e to your computer and use it in GitHub Desktop.
jQueryClassAnim.js
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