/** * 文字或边框等的样式变换 * @param ele 容器的对象 * @param cls 要变化的样式 * @param times 闪烁时间 */ function shake(ele,cls,times){ var i = 0, t = false, o = ele.attr("class")+" ", c = "", times = times||2; if(t) return; t= setInterval(function(){ i++; c = i%2 ? o+cls : o; ele.attr("class",c); if(i==2*times){ clearInterval(t); ele.removeClass(cls); } },200); }; 样例:
shake($("#msg"),"green",6);
<style type="text/css"> .green{color:green;border:1px solid #ff0000}</style>
时间: 2024-10-03 21:25:12