一款轻量级倒计时插件leftTime.js,演示页面给出了6种倒计时效果,并贴出了对应的代码方便调用。
页面的head部分,需引入jQuery库和倒计时插件,并设置好页面的样式,代码如下:
<script type="text/javascript" src="js/jquery.min.js"></script>
<script type="text/javascript" src="js/leftTime.min.js"></script>
<style type="text/css">
*,html,body{padding:0;margin:0;font-size:12px;outline: none;font-family:'Microsoft YaHei','Lantinghei SC','Open Sans',Arial,'Hiragino Sans GB','STHeiti','WenQuanYi Micro Hei','SimSun',sans-serif;}
.wrap-box{width:1100px;min-width:1100px; margin:6% auto;}
h1{line-height:2; font-size:30px; text-align: center; margin-bottom:40px;}
table.data-table{width:100%;}
table.data-table tr:odd{background:#dcebff;}
table.data-table td{line-height:24px;padding:3px;vertical-align: top;}
table.data-table th{height:50px;line-height:50px;padding: 3px;font-size:20px;text-align: left;}
table.data-table .colspan-a{width:35%;}
table.data-table .colspan-b{width:25%;}
table.data-table .colspan-c{width:40%;}
table.data-table td pre{display: block; padding:5px; border: 1px solid #00caff;background: #f8fcff;text-align: left;}
.testBtn-a{display: inline-block;height:30px;line-height:30px;padding:0 10px; border:0; border-radius:5px;color:#fff;background:rgb(65,133,244);cursor: pointer;}
.testBtn-a.on{background:#c9c9c9;color:#666;cursor: default;}
.data-show-box{line-height:30px;}
.date-tiem-span,.date-s-span{display: inline-block;font-size:18px; width:36px; height:30px;line-height:30px; text-align: center; color:#fff; border-radius:5px;}
.date-tiem-span{ background:#333;}
.date-s-span{ background:#f00;}
.date-select-a{margin-right:5px;}
</style>
页面的body部分,需设置好6种倒计时的对应内容,部分代码如下:
<div class="wrap-box">
<h1>轻量级倒计时插件</h1>
<table cellpadding="0" cellspacing="0" class="data-table">
<tr>
<th colspan="3">60秒倒计时</th>
</tr>
<tr>
<td class="colspan-a"><button type="button" class="testBtn-a" id="dateBtn1">获取验证码</button></td>
<td class="colspan-b"></td>
<td class="colspan-c">
<pre>$.leftTime(60,function(d){
//d.status,值true||false,倒计时是否结束;
//d.s,倒计时秒;
});</pre>
</td>
</tr>
<script type="text/javascript">
$(function(){
//60秒倒计时
$("#dateBtn1").on("click",function(){
var _this=$(this);
if(!$(this).hasClass("on")){
$.leftTime(60,function(d){
if(d.status){
_this.addClass("on");
_this.html((d.s=="00"?"60":d.s)+"秒后重新获取");
}else{
_this.removeClass("on");
_this.html("获取验证码");
}
});
}
});
});
</script>
<tr>
<th colspan="3">120秒倒计时</th>
</tr>
<tr>
<td class="colspan-a"><button type="button" class="testBtn-a" id="dateBtnB">获取验证码</button></td>
<td class="colspan-b"></td>
<td class="colspan-c">
<pre>$.leftTime(120,function(d){
//d.status,值true||false,倒计时是否结束;
//parseInt(d.m)*60+parseInt(d.s))+"秒后重新获取";
},true);</pre>
</td>
</tr>
<script type="text/javascript">
$(function(){
//120秒倒计时
$("#dateBtnB").on("click",function(){
var _this=$(this);
if(!$(this).hasClass("on")){
$.leftTime(120,function(d){
if(d.status){
_this.addClass("on");
_this.html((parseInt(d.m)*60+parseInt(d.s))+"秒后重新获取");
}else{
_this.removeClass("on");
_this.html("获取验证码");
}
},true);
}
});
});
</script>
系统已开启自动识别垃圾评论机制,识别到的自动封号,下载出错或者资源有问题请联系全栈客服QQ 1915635791