jQuery倒计时

所属分类:输入-日期和时间

 209200  465  查看评论 (22)
分享到微信朋友圈
X
jQuery倒计时 ie兼容6

实现代码

引用

<script type="text/javascript" src="js/jquery.min.js"></script>

js

<script type="text/javascript">
var intDiff = parseInt(60);//倒计时总秒数量
function timer(intDiff){
	window.setInterval(function(){
	var day=0,
		hour=0,
		minute=0,
		second=0;//时间默认值		
	if(intDiff > 0){
		day = Math.floor(intDiff / (60 * 60 * 24));
		hour = Math.floor(intDiff / (60 * 60)) - (day * 24);
		minute = Math.floor(intDiff / 60) - (day * 24 * 60) - (hour * 60);
		second = Math.floor(intDiff) - (day * 24 * 60 * 60) - (hour * 60 * 60) - (minute * 60);
	}
	if (minute <= 9) minute = '0' + minute;
	if (second <= 9) second = '0' + second;
	$('#day_show').html(day+"天");
	$('#hour_show').html('<s id="h"></s>'+hour+'时');
	$('#minute_show').html('<s></s>'+minute+'分');
	$('#second_show').html('<s></s>'+second+'秒');
	intDiff--;
	}, 1000);
} 
$(function(){
	timer(intDiff);
});	
</script>

html

<h1>网页上的倒计时</h1>
<div class="time-item">
	<span id="day_show">0天</span>
	<strong id="hour_show">0时</strong>
	<strong id="minute_show">0分</strong>
	<strong id="second_show">0秒</strong>
</div>

css

h1 {
	font-family:"微软雅黑";
	font-size:40px;
	margin:20px 0;
	border-bottom:solid 1px #ccc;
	padding-bottom:20px;
	letter-spacing:2px;
}
.time-item strong {
	background:#C71C60;
	color:#fff;
	line-height:49px;
	font-size:36px;
	font-family:Arial;
	padding:0 10px;
	margin-right:10px;
	border-radius:5px;
	box-shadow:1px 1px 3px rgba(0,0,0,0.2);
}
#day_show {
	float:left;
	line-height:49px;
	color:#c71c60;
	font-size:32px;
	margin:0 10px;
	font-family:Arial,Helvetica,sans-serif;
}
.item-title .unit {
	background:none;
	line-height:49px;
	font-size:24px;
	padding:0 10px;
	float:left;
}
相关插件-日期和时间

jQuery扁平化多色时间日历插件ECalendar

基于jQuery开发的CSS3时间日历插件,高效好用,日期时间选择一气呵成。
  日期和时间
 50986  494

jQuery移动端上下滑动日期选择插件mobileSelect.js

jQuery多功能的移动端滚动选择器,支持单选到多选、支持多级级联、提供自定义回调函数等
  日期和时间
 27557  217

jQuery时间轴(原创)

时间轴,可左右点击切换、点击年,切换下面对应的内容
  日期和时间
 32459  372

jquery ui酒店预订日历选择器控件代码

jquery ui酒店预订日历选择器控件代码
  日期和时间
 58074  422

讨论这个项目(22)回答他人问题或分享插件使用方法奖励jQ币 评论用户自律公约

    氵水の雪* 0
    2018/7/17 12:00:46
    多次调用,怎么调呢
    回复
    - 0
    2017/11/8 9:27:46

    楼主,如何解决刷新计时器还原的问题??愿意奉献JQ币,如何解决还原的问题

    回复
    - 0
    2017/11/8 9:26:04

    楼主,如何解决刷新计时器还原的问题??

    回复
    vll。 0
    2017/9/15 16:26:03

    请问怎么控制变成认为启动倒计时的?

    回复
    简单 0
    2017/9/7 13:48:37

    很好,用起来很方便

    回复
    当初人 0
    2016/11/23 10:11:52
    明天的某一时间减去当前时间的总秒数作为intDiff,能不能解决刷新计时还原的问题?? 回复
    a. boy 0
    2016/11/2 9:11:56
    It's Me 0
    2016/3/29 11:03:49
    不错  很实用 使用简单 回复
    小明威武! 0
    2016/3/27 17:03:58
    风格简洁漂亮,很实用,谢谢楼主! 回复
    低整のㄋ低整 0
    2016/1/26 16:01:30

    风格简洁漂亮,很实用,谢谢楼主!

    回复
😃
  • 😀
  • 😉
  • 😥
  • 😵
  • 😫
  • 😘
  • 😡
  • 👍
  • 🌹
  • 👏
  • 🍺
  • 🍉
  • 🌙
  • 💖
  • 💔
😃
  • 😀
  • 😉
  • 😥
  • 😵
  • 😫
  • 😘
  • 😡
  • 👍
  • 🌹
  • 👏
  • 🍺
  • 🍉
  • 🌙
  • 💖
  • 💔
取消回复