javascript實(shí)現(xiàn)倒計(jì)時(shí)提示框
本文實(shí)例為大家分享了javascript實(shí)現(xiàn)倒計(jì)時(shí)提示框的具體代碼,供大家參考,具體內(nèi)容如下

代碼:
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta http-equiv="X-UA-Compatible" content="ie=edge">
<title>全屏提示框</title>
<style>
#button{
width: 150px;
height: 50px;
background-color: greenyellow;
}
.fullScreenDiv{/* 全屏div */
display: none;
position: absolute;
left: 0px;
top: 0px;
width: 100%;
height: 100%;
background-color: rgba(0, 0, 0, 0.4);
}
.promptDiv{/* 提示框div */
display: none;
position: absolute;
left: 50%;
top: 50%;
transform: translateX(-50%) translateY(-50%);
width: 30%;
height: 30%;
border-radius: 20px;
background-color:white;
text-align: center;
}
.close{
height: 34px;
line-height: 34px;
margin: 0px;
text-align: right;
border-top-left-radius: 20px;
border-top-right-radius: 20px;
background-color: cornflowerblue
}
.X{
padding: 2px 6px;
margin-right: 8px;
color: white;
cursor: pointer;
}
.countDown{/*倒計(jì)時(shí)關(guān)閉提示框*/
color: red;
font-size: 28px;
}
</style>
<script>
window.onload=function(){
document.getElementById("button").addEventListener("click",function(){
document.getElementsByClassName("fullScreenDiv")[0].style.display="block";
document.getElementsByClassName("promptDiv")[0].style.display="block";
for(var i=5;i>=0;i--){
(function(i){
setTimeout(function(){
var j=Math.abs(i-5);//如果i為0,那么被定時(shí)0s,則要輸出abs(0-5)=5 ,如果i為5,那么被定時(shí)5s,則要輸出abs(i-5)=0
if(j==0){
document.getElementsByClassName("fullScreenDiv")[0].style.display="none";
document.getElementsByClassName("promptDiv")[0].style.display="none";
}else{
document.getElementsByClassName("countDown")[0].innerHTML=j;
}
},i*1000);//每次間隔時(shí)間為1s
})(i);
}
});
document.getElementsByClassName("X")[0].addEventListener("click",function(){
document.getElementsByClassName("fullScreenDiv")[0].style.display="none";
document.getElementsByClassName("promptDiv")[0].style.display="none";
});
}
</script>
</head>
<body>
<div>
<button id="button">打開全屏提示框</button>
</div>
<div class="fullScreenDiv">
<div class="promptDiv">
<h4 class="close"><span class="X">X</span></h4>
<p>我是全屏提示框我是全屏提示框我是全屏提示框</p>
<p>倒計(jì)時(shí)關(guān)閉</p>
<span class="countDown">5</span>
</div>
</div>
</body>
</html>
以上就是本文的全部?jī)?nèi)容,希望對(duì)大家的學(xué)習(xí)有所幫助,也希望大家多多支持腳本之家。
- javascript實(shí)現(xiàn)倒計(jì)時(shí)并彈窗提示特效
- JS 倒計(jì)時(shí)實(shí)現(xiàn)代碼(時(shí)、分,秒)
- JS實(shí)現(xiàn)倒計(jì)時(shí)(天數(shù)、時(shí)、分、秒)
- 簡(jiǎn)單易用的倒計(jì)時(shí)js代碼
- js代碼實(shí)現(xiàn)點(diǎn)擊按鈕出現(xiàn)60秒倒計(jì)時(shí)
- 2種簡(jiǎn)單的js倒計(jì)時(shí)方式
- 原生JS實(shí)現(xiàn)簡(jiǎn)單的倒計(jì)時(shí)功能示例
- js幾秒以后倒計(jì)時(shí)跳轉(zhuǎn)示例
- 一個(gè)不錯(cuò)的js html頁(yè)面倒計(jì)時(shí)可精確到秒
- js實(shí)現(xiàn)點(diǎn)擊獲取驗(yàn)證碼倒計(jì)時(shí)效果
相關(guān)文章
javascript原生封裝一個(gè)淡入淡出效果的函數(shù)測(cè)試實(shí)例代碼
這篇文章主要介紹了javascript原生封裝一個(gè)淡入淡出效果的函數(shù),主要有FadeIn淡入函數(shù)和FadeOut淡出函數(shù),需要的朋友可以參考下2018-03-03
微信小程序間使用navigator跳轉(zhuǎn)傳值問題實(shí)例分析
這篇文章主要介紹了微信小程序間使用navigator跳轉(zhuǎn)傳值問題,結(jié)合實(shí)例形式分析了微信小程序間使用navigator跳轉(zhuǎn)傳值過程中遇到的問題與解決方法,需要的朋友可以參考下2020-03-03
隨鼠標(biāo)移動(dòng)的時(shí)鐘非常漂亮遺憾的是只支持IE
這篇文章主要介紹了隨鼠標(biāo)移動(dòng)的時(shí)鐘非常漂亮遺憾的是只支持IE,需要的朋友可以參考下2014-08-08
js實(shí)現(xiàn)一款簡(jiǎn)單踩白塊小游戲(曾經(jīng)很火)
本文給大家分享原生js實(shí)現(xiàn)曾經(jīng)很火的一款小游戲—?jiǎng)e踩白塊,代碼簡(jiǎn)單易懂,非常不錯(cuò),具有一定的參考借鑒價(jià)值,需要的朋友參考下吧2019-12-12
使用JavaScript實(shí)現(xiàn)網(wǎng)頁(yè)版Pongo設(shè)計(jì)思路及源代碼分享
Pongo是款很好玩的手欠類游戲,由于在玩的過程中發(fā)現(xiàn)了一些BUG,所以就打算自己也弄個(gè),經(jīng)過一番思索,就有了本文,主要說說實(shí)現(xiàn)這款游戲的設(shè)計(jì)思路以及分享源碼給大家2014-06-06
javascript中setAttribute()函數(shù)使用方法及兼容性
這篇文章主要介紹了javascript中setAttribute()函數(shù)使用方法及兼容性的相關(guān)資料,需要的朋友可以參考下2015-07-07
JS隨機(jī)洗牌算法之?dāng)?shù)組隨機(jī)排序
這篇文章主要介紹了JS隨機(jī)洗牌算法之給數(shù)組隨機(jī)排序的相關(guān)資料,需要的朋友可以參考下2016-03-03
JavaScript字符串String和Array操作的有趣方法
字符串和數(shù)組在程序編寫過程中是十分常用的類型,因此程序語(yǔ)言都會(huì)將String和Array作為基本類型,并提供許多字符串和數(shù)組的方法來簡(jiǎn)化對(duì)字符串的操作2012-12-12
javascript顯示用戶停留時(shí)間的簡(jiǎn)單實(shí)例
這篇文章介紹了javascript顯示用戶停留時(shí)間的簡(jiǎn)單實(shí)例,有需要的朋友可以參考一下2013-08-08

