jQuery實現倒計時效果-楊秀徐

來源:互聯網
上載者:User

標籤:style   blog   http   io   ar   sp   java   on   div   

本執行個體效果:剩餘368天22小時39分57秒結束

代碼簡單易懂,適用各種倒計時;

<!DOCTYPE html><head>    <title>jQuery實現倒計時效果-楊秀徐</title>    <script type="text/javascript" src="/scripts/jquery.js"></script>    <script type="text/javascript">        /*        @楊秀徐,首頁 http://www.gzmsg.com        @用途:jQuery實現倒計時效果$(".time").countDown({time: "2015/12/1 10:00:00",type:0})        @參數:time: 結束時間,type:顯示方式(0顯示天數,1不顯示天數)        */        $.fn.countDown = function (opt) {            var opt = $.extend({                time : null,                type : 0            }, opt);            var edtime   = new Date(opt.time).getTime(),                  //月份是實際月份-1            edsecond = (edtime - new Date().getTime()) / 1000;              var eday    = $(this).find(‘.day‘),                ehour   = $(this).find(‘.hour‘),                eminute = $(this).find(‘.minute‘),                esecond = $(this).find(‘.second‘);            var timer = setInterval(function () {                if (edsecond > 1) {                    edsecond -= 1;                    var day = Math.floor((edsecond / 3600) / 24),                    hour = Math.floor((edsecond / 3600) % 24),                    minute = Math.floor((edsecond / 60) % 60),                    second = Math.floor(edsecond % 60);                    if(opt.type===0){                        $(eday).text(day);                                  //計算天                        $(ehour).text(hour < 10 ? "0" + hour : hour);       //計算小時                    }else{                        hour = day * 24;                        $(ehour).text(hour < 10 ? "0" + hour : hour);       //計算小時-沒有天數                      }                    $(eminute).text(minute < 10 ? "0" + minute : minute);   //計算分鐘                    $(esecond).text(second < 10 ? "0" + second : second);   //計算秒殺                } else {                    clearInterval(timer);                }            }, 1000);        }        $(function () {            $(".time").countDown({                time: "2015/12/1 10:00:00",                type:0            });        });    </script></head><body>    <div class="time">剩餘<span class="day">0</span>天<span class="hour">00</span>小時<span class="minute">00</span>分<span class="second">00</span>秒結束</div></body></html>

 

jQuery實現倒計時效果-楊秀徐

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.