<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>定時器彈框</title>
<style type="text/css">
.pop{
width: 400px;
height: 300px;
background-color: #fff;
border: 1px solid #000;
/*固定定位*/
position: fixed;
/*左上角位于頁面中心*/
left: 50%;
top: 50%;
/*讓div向左偏移半個寬度喧枷、向上偏移半個高度虹统,使div位于頁面中心*/
margin-left: -200px;
margin-top: -150px;
/*彈窗在最上面*/
z-index: 9999;
}
/*遮罩樣式*/
.mask{
position: fixed;
width: 100%;
height: 100%;
background-color: #000;
left: 0;
top: 0;
/*設置透明度30%*/
opacity: 0.3;
filter: alpha(opacity=30);/*兼容IE6、7隧甚、8*/
/*遮罩在彈窗的下面车荔,在網(wǎng)頁所有內容的上面*/
z-index: 9990;
}
.pop_con{
display: none;/*默認不顯示,用定時器顯示*/
}
</style>
<script type="text/javascript">
/*
setTimeout 只執(zhí)行一次的定時器
clearTimeout 關閉只執(zhí)行一次的定時器
setInterval 反復執(zhí)行的定時器
clearInterval 關閉反復執(zhí)行的定時器
*/
window.onload = function(){
var oPop = document.getElementById('pop');
var oShut = document.getElementById('shutOff');
/*setTimeout(showPop, 3000);//開啟定時器戚扳,3秒后調用函數(shù)showPop()彈框
function showPop(){
oPop.style.display = 'block';//顯示彈框和遮罩
}*/
//開啟定時器的簡寫方式:調用匿名函數(shù)
setTimeout(function(){
oPop.style.display = 'block';
}, 3000);
oShut.onclick = function(){
oPop.style.display = 'none';//關閉彈框和遮罩
}
}
</script>
</head>
<body>
<h1>歡迎忧便,我的小公主!</h1>
<p>
? ? ? ? *? *? *? *? ?
? ? ? *? ? * *? ? *? ?
? ? ? *? ★? *? ★? *? ?
? ? ? *? ? ? ★? ? *? ?
>>>------I love you!? ---->
? ? ? ? *? ? ? ? *? ? ?
? ? ? ? ? *? ★ *? ? ?
? ? ? ? ? ? *? *? ? ? ? ?
? ? ? ? ? ? * *? ? ? ? ?
? ? ? ? ? ? ? *? </p>
<a title="小豬佩奇帽借,我配你珠增,高山流水,我留你砍艾,落葉歸根蒂教,我歸你,唐僧取經脆荷,我娶你悴品,">mua</a>
<div class="pop_con" id="pop">
<div class="pop">
<h3>提示信息</h3>
<a href="#" id="shutOff">我也愛你</a>
</div>
<div class="mask"></div>
</div>
</body>
</html>
JS時鐘:
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>時鐘</title>
<style type="text/css">
</style>
<script type="text/javascript">
window.onload = function(){
var oBox = document.getElementById('box');
function timeGo(){
var now = new Date();
// alert(now);//彈出美式時間:Thu Nov 01 2018 14:55:35 GMT+0800 (中國標準時間)
var year = now.getFullYear();//2018年
var month = now.getMonth() + 1;//6月彈出5//范圍0-11
var date = now.getDate();//1號
var week = now.getDay();//4//星期幾,西半球時間,范圍0-6苔严,星期日為一周的第一天,為0
var hour = now.getHours();
var minute = now.getMinutes();
var second = now.getSeconds();
// alert(hour + ":" + minute + ":" + second);//14:56:45
oBox.innerHTML = '當前時間是:' + year + '年' + toDouble(month) + '月' + toDouble(date) + '日 ' + toWeek(week) + ' ' + toDouble(hour) + ":" + toDouble(minute) + ":" + toDouble(second);
}
timeGo();
setInterval(timeGo, 1000);
}
//此函數(shù)將星期的數(shù)字轉為漢字表示
function toWeek(num){
switch(num){
case 0:
return '星期天';
break;
case 1:
return '星期一';
break;
case 2:
return '星期二';
break;
case 3:
return '星期三';
break;
case 4:
return '星期四';
break;
case 5:
return '星期五';
break;
case 6:
return '星期六';
break;
}
}
//此函數(shù)將不足兩位的數(shù)字前面補0
function toDouble(num){
if(num < 10){
return '0' + num;
}else{
return num;
}
}
</script>
</head>
<body>
<div id="box"></div>
</body>
</html>
JS倒計時:
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>倒計時</title>
<script type="text/javascript">
window.onload = function(){
//活動第二天要將頁面下線孤澎,直接跳轉到其它頁面届氢,不會走后面的代碼了
// window.location.;
var oDiv = document.getElementById('div1');
function timeLeft(){
//實際開發(fā)中此時間從服務器獲取,避免客戶端調整時間
var now = new Date();
var future = new Date(2018,10,10,24,00,00);//就是2018年11月11號
0
// alert(future - now);//彈出與當前時間相差的毫秒數(shù):12469935436
var milli = parseInt((future - now)/1000);
//活動當天頁面下線覆旭,避免倒計時到點后繼續(xù)計負時
// if(milli <= 0){
// //頁面跳轉退子,不執(zhí)行下面的代碼了
// window.location.;
// }
var day = parseInt(milli / 86400);
var hour = parseInt(milli % 86400 / 3600);
var minute = parseInt(((milli % 86400) % 3600) / 60);
var second = milli % 60;
oDiv.innerHTML = '距離2018年11月11日00時00分00秒還有' + day + '天' + toDouble(hour) + '時' + toDouble(minute) + '分' + toDouble(second) + '秒';//距離2018年11月11日00時00分00秒還有10天08時48分00秒
}
timeLeft();
setInterval(timeLeft, 1000);
}
function toDouble(num){
if(num < 10){
return '0' + num;
}else{
return num;
}
}
</script>
</head>
<body>
<div id="div1"></div>
</body>
</html>