JS實(shí)現(xiàn)定時(shí)自動(dòng)消失的彈出窗口
一、Demo.html
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>js彈框3秒后自動(dòng)消失</title>
<link rel="stylesheet" type="text/css" href="./js/bootstrap/css/bootstrap.css" rel="external nofollow" />
<link rel="stylesheet" type="text/css" href="./css/demo.css" rel="external nofollow" />
</head>
<body>
<button onclick="showModal()">點(diǎn)擊彈出模態(tài)框</button>
<div class='modal my-modal-alert' id='my-modal-alert'>
<div class='modal-dialog boxBodySmall'>
<div class='modal-content'>
<div class='modal-header boxHeader'>
<button type='button' class='close boxClose' data-dismiss='modal'>
<span aria-hidden='true'>×</span><span class='sr-only'>Close</span>
</button>
<h4 class='modal-title boxTitle' id='modal-title'>模態(tài)框</h4>
</div>
<div class='modal-body' id='modal-body-alert'>
<div id='modal_message'>js彈框自動(dòng)消失案例</div>
<span id='num'></span>
</div>
<div class='modal-footer boxFooter' id='modal-footer'>
<button type='button' class='btn btn-default boxButton' data-dismiss='modal'>關(guān)閉</button>
<button type='button' class='btn btn-primary boxButton'>保存</button>
</div>
</div>
</div>
</div>
<script src="./js/jquery/jquery-1.11.2.js"></script>
<script src="./js/bootstrap/js/bootstrap.min.js"></script>
<script src="./js/jquery-ui/jquery-ui.min.js"></script>
<script>
var clearFlag = 0;
var count = 3;//設(shè)置3秒后自動(dòng)消失
var showModal = function(){
$("#my-modal-alert").toggle();//顯示模態(tài)框
$("#my-modal-alert").draggable({//設(shè)置模態(tài)框可拖動(dòng)(需要引入jquery-ui.min.js)
handle: ".modal-header"
});
clearFlag = self.setInterval("autoClose()",1000);//每過一秒調(diào)用一次autoClose方法
}
var autoClose = function(){
if(count>0){
$("#num").html(count + "秒后窗口將自動(dòng)關(guān)閉");
count--;
}else if(count<=0){
window.clearInterval(clearFlag);
$("#num").html("");
$("#my-modal-alert").fadeOut("slow");
count = 3;
$("#my-modal-alert").toggle();
}
}
</script>
</body>
</html>注意:1、bootstrap依賴于jquery,引入bootstrap前需要引入jquery
二、Demo.css
/*彈框本身(大)*/
.my-modal-alert .boxBodyBig{
width:496px;
height: 418px;
}
/*彈框本身(小)*/
.my-modal-alert .boxBodySmall{
width:412px;
height: 418px;
}
/*彈框頭*/
.my-modal-alert .boxHeader{
background-color: #f6f6f6;
border-bottom: #e5e5e5 1px;
height: 48px;
}
/*彈框標(biāo)題*/
.my-modal-alert .boxTitle{
background-color: #f6f6f6;
color:#333333;
font-family:"SimHei";
font-size: 16px;
}
/*彈框頭部分右側(cè)關(guān)閉按鈕*/
.my-modal-alert .boxClose{
}
.my-modal-alert .boxClose:hover{
color: #ff7800;
}
/*彈框按鈕的父級(jí)元素塊*/
.my-modal-alert .boxFooter{
margin: auto;
text-align: center;
padding:24px 15px 24px 15px;
margin:0px 15px 0px 15px;
}
/*彈框按鈕*/
.my-modal-alert .boxButton{
font-family:"SimHei";
background-color:#ff7800;
width: 70px;
height: 30px;
color:white;
text-align:center;
line-height: 1;
}
/*已下為選用*/
/*彈框主題label框*/
.my-modal-alert .boxLabel{
width:80px;
font-size: 14px;
font-family:'SimHei';
color: #999999;
}
/*文本框*/
.my-modal-alert .boxInput{
width:176px;
font-size: 14px;
color: #333333;
}
/*純文本*/
.my-modal-alert .boxText{
color:#ff7800;
font-family:'SimHei';
font-size: 12px;
}
.my-modal-alert .boxTextarea{
font-size: 12px;
}
.my-modal-alert .modal-body{
width: 400px;
height: 100px;
text-align: center;
}
.my-modal-alert .modal_message{
margin-top: 20px;
}以上就是本文的全部?jī)?nèi)容,希望對(duì)大家的學(xué)習(xí)有所幫助,也希望大家多多支持腳本之家。
相關(guān)文章
JavaScript開發(fā)人員的10個(gè)關(guān)鍵習(xí)慣小結(jié)
還在一味沒有目的的編寫JavaScript代碼嗎?那么你就OUT了!讓我們一起來(lái)看看小編為大家搜羅的JavaScript開發(fā)人員應(yīng)該具備的十大關(guān)鍵習(xí)慣吧2014-12-12
利用prop-types第三方庫(kù)對(duì)組件的props中的變量進(jìn)行類型檢測(cè)
本篇文章主要介紹了利用prop-types第三方庫(kù)對(duì)組件的props中的變量進(jìn)行類型檢測(cè)的相關(guān)知識(shí),具有很好的參考價(jià)值。下面跟著小編一起來(lái)看下吧2017-05-05
JavaScript實(shí)現(xiàn)網(wǎng)頁(yè)留言板功能
這篇文章主要為大家詳細(xì)介紹了JavaScript實(shí)現(xiàn)網(wǎng)頁(yè)留言板功能,文中示例代碼介紹的非常詳細(xì),具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下2020-11-11
Three.js中的紋理圖像應(yīng)用和屬性調(diào)整方法
在three.js中紋理貼圖是用來(lái)給物體表面添加圖案、顏色或者其他視覺效果的一種技術(shù),這篇文章主要給大家介紹了關(guān)于Three.js中紋理圖像應(yīng)用和屬性調(diào)整的相關(guān)資料,需要的朋友可以參考下2024-01-01
JavaScript中scrollTo()無(wú)效問題處理辦法
這篇文章主要給大家介紹了關(guān)于JavaScript中scrollTo()無(wú)效問題處理辦法,scrollTo()方法將文檔滾動(dòng)到指定的坐標(biāo),如需使 scrollTo()方法起作用,文檔必須大于屏幕,并且滾動(dòng)條必須可見,需要的朋友可以參考下2024-01-01
微信小程序開發(fā)之麥克風(fēng)動(dòng)畫 幀動(dòng)畫 放大 淡出
本篇文章主要介紹了微信小程序開發(fā)之麥克風(fēng)動(dòng)畫:幀動(dòng)畫、放大、淡出的相關(guān)資料。具有很好的參考價(jià)值。下面跟著小編一起來(lái)看下吧2017-04-04
javascript實(shí)現(xiàn)禁止復(fù)制網(wǎng)頁(yè)內(nèi)容匯總
本文給大家匯總介紹了幾種使用javascript和CSS實(shí)現(xiàn)禁止復(fù)制頁(yè)面內(nèi)容的方法,非常的實(shí)用,有需要的小伙伴可以參考下。2015-12-12
JavaScript 對(duì)象模型 執(zhí)行模型
簡(jiǎn)單數(shù)值類型: 有Undefined, Null, Boolean, Number和String。注意,描述中的英文單詞在這里僅指數(shù)據(jù)類型的名稱,并不特指JS的全局對(duì)象N an, Boolean, Number, String等,它們?cè)诟拍钌系膮^(qū)別是比較大的。2010-10-10
js使用對(duì)象直接量創(chuàng)建對(duì)象的代碼
js使用對(duì)象直接量創(chuàng)建對(duì)象的代碼...2007-09-09

