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

jquery——警示灯特效

2019-10-25 12:09 2306 查看

GFT动态效果图:

 

代码:

<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title></title>
<script src="jquery.js"></script>
<style>
.blue{
height: 50px;
width: 40px;
background-color: blue;
border-radius: 20px 20px 2px 2px;
}
.red{
height: 50px;
width: 40px;
background-color: red;
border-radius: 20px 20px 2px 2px;
}
</style>
</head>
<body>
<div class="blue"></div><br/>
<input type="button" id="close" value="关闭" />
<input type="button" id="open" value="打开" />
<script type="text/javascript">
//定义定时器对象
var interval;
//打开定时器
function open(){
if(interval != undefined){
alert("已经启动!");
}else{
interval = setInterval(function(){
$("div").toggleClass("red");
},100);
}
}
//关闭定时器
function close(){
clearInterval(interval);
interval = undefined;
}
$(function(){
//关闭按钮绑定点击事件
$("#close").click(function(){
close();
});
//打开按钮绑定点击事件
$("#open").click(function(){
open();
});
});
</script>
</body>
</html>

 

内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签:  jQuery