jquery网页倒计时效果,秒杀,限时抢购!

简介:

422101-20160804163902653-1300920212.png

<!doctype html>
<html>

<head>
    <meta charset="utf-8">
    <title>jquery版的网页倒计时效果</title>
    <meta http-equiv="Content-type" content="text/html;charset=UTF-8" />
    <meta content="width=device-width, initial-scale=1.0, minimum-scale=1.0, maximum-scale=1.0,user-scalable=no" name="viewport" id="viewport">
    <meta name="format-detection" content="telephone=no" />
    <meta content="yes" name="apple-mobile-web-app-capable" />
    <meta content="black" name="apple-mobile-web-app-status-bar-style" />
    <style type="text/css">
    .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;
    }
    </style>
    <script type="text/javascript" src="js/jquery.min.js"></script>
    <script type="text/javascript">
    var intDiff = parseInt(500000); //倒计时总秒数量

    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>
</head>

<body>
    <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>
    <!--倒计时模块-->
</body>

</html>

改造,支持多个倒计时同时进行!

<!doctype html>
<html>

<head>
    <meta charset="utf-8">
    <title>jquery版的网页倒计时效果</title>
    <meta http-equiv="Content-type" content="text/html;charset=UTF-8" />
    <meta content="width=device-width, initial-scale=1.0, minimum-scale=1.0, maximum-scale=1.0,user-scalable=no" name="viewport" id="viewport">
    <meta name="format-detection" content="telephone=no" />
    <meta content="yes" name="apple-mobile-web-app-capable" />
    <meta content="black" name="apple-mobile-web-app-status-bar-style" />
    <style type="text/css">
    .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;
    }
    </style>
    <script type="text/javascript" src="js/jquery.min.js"></script>
    <script type="text/javascript">
    var firstIntDiff = parseInt(500000); //倒计时总秒数量
    var secondIntDiff = parseInt(5000); //倒计时总秒数量

    function timer(intDiff,idName) {
        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;
            $(idName+' .day_show').html(day + "天");
            $(idName+' .hour_show').html('<s id="h"></s>' + hour + '时');
            $(idName+' .minute_show').html('<s></s>' + minute + '分');
            $(idName+' .second_show').html('<s></s>' + second + '秒');
            intDiff--;
        }, 1000);
    }

    $(function() {
        timer(firstIntDiff,'#first');
        timer(secondIntDiff,'#second');
    });
    </script>
</head>

<body>
    <div id="first" class="time-item">
        <span class="day_show">0天</span>
        <strong class="hour_show">0时</strong>
        <strong class="minute_show">0分</strong>
        <strong class="second_show">0秒</strong>
    </div>
    <!--倒计时模块-->
    <div id="second" class="time-item">
        <span class="day_show">0天</span>
        <strong class="hour_show">0时</strong>
        <strong class="minute_show">0分</strong>
        <strong class="second_show">0秒</strong>
    </div>
</body>

</html>

422101-20160804164816153-63225215.png



本文转自TBHacker博客园博客,原文链接:http://www.cnblogs.com/jiqing9006/p/5737312.html,如需转载请自行联系原作者

相关文章
|
3月前
|
JavaScript
实现一个网页同时调用多个倒计时 jquery/js
实现一个网页同时调用多个倒计时 jquery/js
|
7月前
|
JavaScript 搜索推荐 Windows
基于jquery开发的Windows 12网页版
基于jquery开发的Windows 12网页版
53 0
基于jquery开发的Windows 12网页版
|
7月前
|
JavaScript
通俗易懂的jquery倒计时demo效果示例(整理)
通俗易懂的jquery倒计时demo效果示例(整理)
|
JavaScript 前端开发
某东网页(动态)搭建(jquery)
网页编程实战三: 利用jquery实现京东网页(动态)搭建,
某东网页(动态)搭建(jquery)
|
JavaScript
按钮被点击后屏蔽点击且倒计时60S能再次被点击-JS实现和JQuery实现
按钮被点击后屏蔽点击且倒计时60S能再次被点击-JS实现和JQuery实现
124 0
按钮被点击后屏蔽点击且倒计时60S能再次被点击-JS实现和JQuery实现
|
JavaScript
jQuery经典案例【倒计时】
jQuery经典案例【倒计时】
98 0
jQuery经典案例【倒计时】
|
前端开发 JavaScript Java
html2canvas+jQuery+SpringMVC 实现网页转图片并保存到服务器
前端使用的是 RequireJS + jQuery 后端使用的是 SpringMVC + MyBatis 涉及资料 html2canvas 官网 将转换后的图片存储服务器的参考 将网页转换为图片 下载插件包 html2canvas 目前最新版是 v-1.
3138 0
|
JavaScript
jquery实现的让图片在网页的可视区域里四处漂浮的效果
  本文分享给大家一个用jquery开发的图片漂浮效果。 jquery图片漂浮效果,常见的就是网页里四处漂来漂去的广告了,漂到边缘时还会反弹和拐弯。 下面来看具体的代码,先看要实现漂亮效果的这个jquery插件的源码: (function($){ $.
1618 0