Javascript 漂浮 倒计时 <script>
var DaoJiShi={ xPos:300,//起始位置X轴 yPos:200,//起始位置Y轴 step:1, delay:40, height:30,//高度 width:150,//宽度 Hoffset:0, Woffset:0, yon:0, xon:0, pause:true, interval:null, div:null, //this.div.style.top = this.yPos; changePos:function(){ this.width = document.body.clientWidth; this.height = document.body.clientHeight; this.Hoffset = this.div.offsetHeight; this.Woffset = this.div.offsetWidth; this.div.style.backgroundColor="#f7f7f7";//背景色 this.div.style.textAlign="center"; this.div.style.fontSize="12px"; this.div.style.fontWeight="bold"; this.div.style.lineHeight="30px"; this.div.style.border="solid 2px #e7e7e7"; this.div.style.left = this.xPos + document.body.scrollLeft; this.div.style.top = this.yPos + document.body.scrollTop; this.div.innerHTML=this.djs(); if (this.yon){this.yPos = this.yPos + this.step;} else{this.yPos = this.yPos - this.step;} if (this.yPos < 0){this.yon = 1;this.yPos = 0;} if (this.yPos >= (this.height - this.Hoffset)){this.yon = 0;this.yPos = (this.height - this.Hoffset);} if (this.xon) {this.xPos = this.xPos + this.step;} else {this.xPos = this.xPos - this.step;} if (this.xPos < 0) {this.xon = 1;this.xPos = 0;} if (this.xPos >= (this.width - this.Woffset)){this.xon = 0;this.xPos = (this.width - this.Woffset);} if(!this.pause){setTimeout('DaoJiShi.changePos()',this.delay);} }, init:function(){ this.aa=this; this.pause=false; this.div = document.createElement('div'); this.div.style.position="absolute"; this.div.style.width=this.width+"px"; this.div.style.height=this.height+"px"; this.div.innerHTML=this.djs(); document.body.appendChild(this.div); this.div.visibility = "visible"; this.changePos(); }, pause_resume:function(){ if(!this.pause){ this.pause = true; } }, start:function(){this.init()}, djs:function(){ var now = new Date(); var year = now.getFullYear(); //getFullYear getYear var month = now.getMonth(); var date = now.getDate(); var day = now.getDay(); var hour = now.getHours(); var minu = now.getMinutes(); var sec = now.getSeconds(); var day1=new Date('10/1/2009');/*到倒计时的日期*/ var H1=0 ;/*到倒计时的日期指定的几点*/ var M1=0 ;/*到倒计时的日期几份*/ var S1=0 ;/*到倒计时的日期几秒*/ var MI var week; month = month+1; if(month<10)month="0"+month; if(date<10)date="0"+date; if(hour<10)hour="0"+hour; if(minu<10)minu="0"+minu; if(sec<10)sec="0"+sec; var arr_week = new Array("星期日","星期一","星期二","星期三","星期四","星期五","星期六"); week = arr_week[day]; var time = ""; time = "当前时间:"+year+"年"+month+"月"+date+"日"+" "+hour+":"+minu+":"+sec+" "+week; ms =Math.floor((day1-now)/1000) /*到指定的那天0点0分0秒所剩下秒数*/ D2 =Math.floor(ms / 86400); /*天数*/ H2= Math.floor((ms-D2*86400)/3600) M2=Math.floor((ms-D2*86400-H2*3600)/60) S2=ms-D2*86400-H2*3600-M2*60+1 S=S2+S1 M=M1+M2 H=H2+H1 if(S>59)M=M+1; if(S>59)S=S-60; if(M>59)H=H+1; if(M>59)M=M-60; if(H>23)D2=D2+1; if(H>23)H=H-24; time2 = D2+"天"+H+"小时"+M+"分"+S+"秒"; return time2; } }; DaoJiShi.start(); //欢迎加入我的 Javascript 俱乐部:http://tieba.baidu.com/club/5312493,让我们一起学习Javascript </script> |
|
来自: Ding_GY > 《[C] JavaScript》