您的位置:首页 > Web前端 > JQuery

jquery文本闪烁

2015-12-02 15:27 721 查看
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
<title>jquery文字闪烁</title>
<meta name="description" content="">
<meta name="keywords" content="">
<link href="" rel="stylesheet">
<style>
*{magin:0;padding: 0;}
body {
font-family: Arial,Helvetica,sans-serif;
background: #f9f9f9;
font-size: 14px;
color: #333;
}
.main {
width: 600px;
background: #fff;
margin: 0 auto;
padding: 20px 0;
border: solid #ddd;
border-width: 0 1px;
min-height: 800px;
}
.cssFlash {
width: 240px;
height: 26px;
line-height: 26px;
background: #f0f0f0;
border: 1px solid #ddd;
text-align: center;
font-size: 14px;
margin: 20px auto;
}
input.cssFlash {
width: 240px;
font-weight: 900;
color: #999;
display: block;
background: #fff;
text-align: left;
}
.red {
border: 1px solid #d00;
background: #ffe9e8;
color: #d00;
}
input.red {
background: #ffe9e8;
}
#id-div-clickFlash {cursor: pointer;}
.des {
margin: 0 20px;
padding: 6px;
line-height: 20px;
border: 1px solid #ccc;
color: #555;
}
</style>
</head>
<body>
<div class="main">
<div id="id-div-autoFlash" class="cssFlash">文本自动闪动</div>
</div>
<script src="http://cdn.bootcss.com/jquery/1.10.1/jquery.js"></script>
<script>
$(function(){
function textFlash(obj,cssName,times){
var i=0,t=false,o=obj.attr("class")+" ",c="",times=times||2;
if(t) return;
t=setInterval(function(){
i++;
c=i%2?o+cssName:o;  //给偶数次添加两个样式,给奇数次添加一个样式
//alert("c=="+c);
obj.attr("class",c);
if(i==2*times){
clearInterval(t);
obj.removeClass(cssName);
}

},200);
};
textFlash($("#id-div-autoFlash"),"red",3);

});
</script>
</body>
</html>
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签:  jquery 文字特效