1 /** 2 * 闪烁效果 3 * ele dom层 4 * cls 新class 5 * times 变换时间 6 */ 7 function shake(ele,cls,times){ 8 var i = 0; 9 var t= false; 10 var o =ele.attr("class")+" "; 11 var c =""; 12 times = times||2; 13 if(t) return; 14 t= setInterval(function(){ 15 i++; 16 c = i%2 ? o+cls : o; 17 ele.attr("class",c); 18 if(i==2*times){ 19 clearInterval(t); 20 ele.removeClass(cls); 21 } 22 },200); 23 } 24 25 方法调用: shake($(".introduction"), "red", 10);