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 = "當(dāng)前時間:"+year+"年"+month+"月"+date+"日"+" "+hour+":"+minu+":"+sec+" "+week;
ms =Math.floor((day1-now)/1000) /*到指定的那天0點0分0秒所剩下秒數(shù)*/
D2 =Math.floor(ms / 86400); /*天數(shù)*/
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,讓我們一起學(xué)習(xí)Javascript
</script>
本站僅提供存儲服務(wù),所有內(nèi)容均由用戶發(fā)布,如發(fā)現(xiàn)有害或侵權(quán)內(nèi)容,請
點擊舉報。