JS實(shí)現(xiàn)定時自動消失的彈出窗口
一、Demo.html
<!DOCTYPE html> <html> <head> <meta charset="UTF-8"> <title>js彈框3秒后自動消失</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彈框自動消失案例</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秒后自動消失 var showModal = function(){ $("#my-modal-alert").toggle();//顯示模態(tài)框 $("#my-modal-alert").draggable({//設(shè)置模態(tài)框可拖動(需要引入jquery-ui.min.js) handle: ".modal-header" }); clearFlag = self.setInterval("autoClose()",1000);//每過一秒調(diào)用一次autoClose方法 } var autoClose = function(){ if(count>0){ $("#num").html(count + "秒后窗口將自動關(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; } /*彈框按鈕的父級元素塊*/ .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; }
以上就是本文的全部內(nèi)容,希望對大家的學(xué)習(xí)有所幫助,也希望大家多多支持腳本之家。
相關(guān)文章
QQ強(qiáng)制聊天功能代碼(加強(qiáng)版,兼容QQ2010)
QQ強(qiáng)制聊天功能代碼,腳本之家以前也發(fā)布過,但已經(jīng)不能用了,這個是新版本,經(jīng)過測試,完全兼容新版本的qq.2010-06-06window.print打印指定div指定網(wǎng)頁指定區(qū)域的方法
這篇文章主要介紹了window.print打印指定div指定網(wǎng)頁指定區(qū)域的方法,需要的朋友可以參考下2014-08-08JS實(shí)現(xiàn)同一DOM元素上onClick事件與onDblClick事件并存的解決方法
這篇文章主要介紹了JS實(shí)現(xiàn)同一DOM元素上onClick事件與onDblClick事件并存的解決方法,結(jié)合實(shí)例形式分析了javascript通過針對單擊onclick事件增加定時器進(jìn)行onClick事件與onDblClick事件的區(qū)別判定操作,需要的朋友可以參考下2018-06-06JavaScript 冒泡排序和選擇排序的實(shí)現(xiàn)代碼
本文通過實(shí)例代碼給大家介紹了js冒泡排序和選擇排序的實(shí)現(xiàn)代碼,代碼簡單易懂,非常不錯,具有參考借鑒價值,感興趣的朋友一起學(xué)習(xí)吧2016-09-09JavaScript實(shí)現(xiàn)翻頁功能(附效果圖)
這篇文章主要介紹了JavaScript實(shí)現(xiàn)翻頁功能(附效果圖),在項(xiàng)目需求中經(jīng)常遇到,今天小編抽時間給大家分享JavaScript實(shí)現(xiàn)翻頁功能實(shí)例代碼,需要的朋友參考下吧2017-02-02js實(shí)現(xiàn)點(diǎn)擊左右按鈕輪播圖片效果實(shí)例
這篇文章主要介紹了js實(shí)現(xiàn)點(diǎn)擊左右按鈕輪播圖片效果的方法,涉及click事件相應(yīng)、animate方法等使用技巧,需要的朋友可以參考下2015-01-01