jQuery簡單倒計時外掛程式

來源:互聯網
上載者:User

標籤:計算   param   mat   cti   支援   使用   query   ++   class   

 

1. 按照特定的類結構布局。

2. 需要先引入jQuery,再引入此檔案。

 

/** * 簡單倒計時 *  * 支援頁面內同時存在多個計時器並且不互相干擾 * * Usage: *  *         <div class="timer-simple-seconds" timer="3600"> *            <span class="hour">hour</span>小時<span class="minute">minute</span>分<span class="second">second</span>秒 *        </div> *  */$(function(){        //對所有的計時器進行處理    var timers=$(".timer-simple-seconds");    for(var i=0;i<timers.length;i++){        //先調用一次,避免誤差        processTimer($(timers[i]));        setInterval(processTimer,1000,$(timers[i]));    }        /**     * 對時間進行處理     * @param {Object} timer     */    function processTimer(timer){        var total=parseInt(timer.attr("timer"));                //倒計時不能為負        if(total<0) return;                //找到顯示時分秒的元素        var hour=timer.find(".hour");        var minute=timer.find(".minute");        var second=timer.find(".second");                //計算應該顯示的數值        var h=Math.floor(total/(60*60));        var m=Math.floor(Math.floor((total-h*60*60)/60));        var s=total-h*60*60-m*60;                //補位        if(m<10) m="0"+m;        if(s<10) s="0"+s;                //顯示        hour.text(h);        minute.text(m);        second.text(s);                //記錄數值,留待下次使用        total--;        timer.attr("timer",total);    }    });

 

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.