文章搜索:
打开支付宝首页搜索“510617664”,即可领红包
  首页--> 计算机--> FLASH教程
 
倒计时代码
http://www.xxqqss.com 学习轻松网 点击量:5432
 

<style>
div{}
button{}
</style>
<div id="dd">&nbsp;</div>
<script type="text/javascript">
<!--
String.prototype.format = function(){
 var tmpStr = this;
 var iLen = arguments.length;
 for(var i=0;i<iLen;i++){
  tmpStr = tmpStr.replace(new RegExp("\\{" + i + "\\}", "g"), arguments[i]);
 }
 return tmpStr;
}
Number.prototype.We = function(bt){
 var byte = bt || 2;
 var data = this.toString();
 return (new Array(byte + 1).join("0") + data).substring(data.length);
}
function $() {
  var elements = new Array();
  for (var i = 0; i < arguments.length; i++) {
    var element = arguments[i];
    if (typeof element == ’string’)
      element = document.getElementById(element);
    if (arguments.length == 1) 
      return element;
    elements.push(element);
  }
return elements;
}
function CountDown(){
 var ref = this;
 var temp = "";
 this.Timer = null;
 this.Max = 0;
 this.Current = 0;
 this.Element = null;
 this.Format = "mm:ss";
 this.Step = 1000;
 function formatDate(template, input){
  var day = input / 60 /60 /24 | 0;
  var hour = (input - day * 60* 60 * 24) / 60 /60 | 0;
  var minute = (input - day * 60* 60 * 24 - hour * 60 * 60) / 60 | 0;
  var second = input - day * 60* 60 * 24 - hour * 60 * 60 - minute * 60;
  if(temp == ""){
   temp = template.replace(/dd/g, "{0}").replace(/d/g, "{1}");
   temp = temp.replace(/hh/g, "{2}").replace(/h/g, "{3}");
   temp = temp.replace(/mm/g, "{4}").replace(/m/g, "{5}");
   temp = temp.replace(/ss/g, "{6}").replace(/s/g, "{7}");
  }
  return temp.format(day.We(), day, hour.We(), hour, minute.We(), minute, second.We(), second)
 }
 this.Reset = function(){
  this.Clear();
  this.Current = this.Max;
 }
 this.Create = function(element){
  if(typeof(element) == "string"){
   if($(element) == null)document.write("<div id=\"{0}\"></div>".format(element));
   this.Element = $(element);
  } else this.Element = element;
 }
 this.Start = function(){
  this.OnBeforeStart();
  this.Clear();
  if(this.Current == 0)this.Current = this.Max;
  this.Timer = setInterval(this.ShowText, this.Step);
 }
 this.Stop = function(){
  this.Reset();
  this.OnStop();
 }
 this.Pause = function(){
  this.Clear();
  this.OnPause();
 }
 this.Clear = function(){
  if(this.Timer != null)clearInterval(this.Timer);
 }
 this.ShowText = function(){
  with(ref){
   if(--Current > -1) Element.innerText = formatDate(Format, Current);
   else {Clear();OnTimeOut();};
  }
 }
 this.OnBeforeStart = function(){}
 this.OnStop = function(){}
 this.OnPause = function(){}
 this.OnTimeOut = function(){}
 this.toString = function(){
  return "DHTML CountDown";
 }
}
var cd = new CountDown();
cd.Create("ddd");
cd.Max = 60;
cd.Start();
cd.OnTimeOut = function(){alert("时间到!");}
var cd1 = new CountDown();
cd1.Format = "d天 h小时:mm:ss";
cd1.Create("dd");
cd1.Max = 300000;
cd1.Start();
//-->
</script>
<button onclick="cd.Pause()">Time2 Pause</button>
<button onclick="cd.Start()">Time2 Start</button>
<div contentEditable style="ime-mode:Disabled">123</div>
<input style="ime-mode:Disabled" value="123">

作者:我佛山人  来源:闪吧


打印】 【关闭
免责声明 :本站刊载此文不代表同意其说法或描述,仅为提供更多信息,也不构成任何建议。对本文有任何异议,请发送fiyeadwyv@163.com
最热门点击排行
 
版权所有 2006-2021:学习轻松网 Copyright http://www.xxqqss.com All rights reserved 浙ICP备14013707号-1
广告联系电话: 13958357030 联系QQ:9792414 工具条下载