欧美bbbwbbbw肥妇,免费乱码人妻系列日韩,一级黄片

自己封裝的一個(gè)簡(jiǎn)單的倒計(jì)時(shí)功能實(shí)例

 更新時(shí)間:2016年11月23日 10:27:08   投稿:jingxian  
下面小編就為大家?guī)?lái)一篇自己封裝的一個(gè)簡(jiǎn)單的倒計(jì)時(shí)功能實(shí)例。小編覺(jué)得挺不錯(cuò)的,現(xiàn)在就分享給大家,也給大家做個(gè)參考。一起跟隨小編過(guò)來(lái)看看吧

因?yàn)槠匠9ぷ髦泻艹S玫皆摴δ埽跃屠眠@次國(guó)慶假期,重新梳理與對(duì)原有代碼進(jìn)行改善,再集成一個(gè)常用的功能,最終封裝出這個(gè)“簡(jiǎn)單倒計(jì)時(shí)”功能。

該倒計(jì)時(shí)方法具有以下該功能:

1. 根據(jù)指定日期與當(dāng)前的電腦時(shí)間進(jìn)行匹配

2. 通過(guò)指定一個(gè)數(shù)組參數(shù),來(lái)設(shè)置在每一天內(nèi)不同的時(shí)間段進(jìn)行倒計(jì)時(shí)。

* 該方法還未通過(guò)實(shí)際工作的檢測(cè),穩(wěn)定性未知(如果實(shí)際工作通過(guò),會(huì)刪除這段話)

function countDown(date,target,filter){

  var setTime = new Date(date).getTime(),
    timer = null;

  function core(){
    var nowTime = new Date().getTime(),
      leftTime = 0,
      d = 0,h = 0,m = 0,s = 0;

    ////////////////////////////
    //conditation @ doublue time
    if(filter.length){
      setTime = new Date();
      for(var i=0,l=filter.length;i<l;i++){
        setTime.setHours(filter[i]);
        setTime.setMinutes(0);
        setTime.setSeconds(0);
        if(nowTime < setTime.getTime()){
          break;
        }else if(i == filter.length-1){
          setTime.setDate(setTime.getDate()+1);
          setTime.setHours(filter[0]);
        }
        
      }
    }
    ////////////////////////////

    leftTime = Math.ceil((setTime - nowTime)/1000);
    if(nowTime <= setTime){
      d = ~~(leftTime/86400);
      h = ~~(leftTime%86400/3600);
      m = ~~(leftTime%86400%3600/60);
      s = ~~(leftTime%86400%3600%60);
      timer = setTimeout(core,1e3);
    }else{
      clearTimeout(timer);
      timer = null;
    }

    //here set out format
    target.innerHTML = 'd:'+d+' h:'+h+' m:'+m+' s:'+s;
    
  }
  core();
}

調(diào)用方式:

// 普通調(diào)用
countDown('2016/10/02/23:43',oDiv);
// 指定時(shí)間循環(huán)倒計(jì)時(shí)
countDown('2016/10/02/23:43',oDiv,[9,11,18]);

以上這篇自己封裝的一個(gè)簡(jiǎn)單的倒計(jì)時(shí)功能實(shí)例就是小編分享給大家的全部?jī)?nèi)容了,希望能給大家一個(gè)參考,也希望大家多多支持腳本之家。

相關(guān)文章

最新評(píng)論