js右下角彈出提示框示例代碼
本文實例講解了網(wǎng)頁右下角彈出廣告信息框?qū)嵗a,分享給大家供大家參考,具體內(nèi)容如下
效果圖:
具體代碼:
<!DOCTYPE html> <html> <head> <meta charset="gb2312"> <title>網(wǎng)頁右下角的信息框</title> </head> <style type="text/css"> #winpop { width:200px; height:0px; position:absolute; right:0; bottom:0; border:1px solid #666; margin:0; padding:1px; overflow:hidden; display:none; } #winpop .title{ width:100%; height:22px; line-height:20px; background:#FFCC00; font-weight:bold; text-align:center; font-size:12px; } #winpop .con{ width:100%; height:90px; line-height:80px; font-weight:bold; font-size:12px; color:#FF0000; text-decoration:underline; text-align:center } #silu{ font-size:12px; color:#666; position:absolute; right:0; text-decoration:underline; line-height:22px; } .close{ position:absolute; right:4px; top:-1px; color:#FFF; cursor:pointer } </style> <script type="text/javascript"> function tips_pop(){ var MsgPop=document.getElementById("winpop"); var popH=parseInt(MsgPop.style.height);//將對象的高度轉(zhuǎn)化為數(shù)字 if(popH==0){ MsgPop.style.display="block";//顯示隱藏的窗口 show=setInterval("changeH('up')",2); } else{ hide=setInterval("changeH('down')",2); } } function changeH(str){ var MsgPop=document.getElementById("winpop"); var popH=parseInt(MsgPop.style.height); if(str=="up"){ if(popH<=100){ MsgPop.style.height=(popH+4).toString()+"px"; } else{ clearInterval(show); } } if(str=="down"){ if(popH>=4){ MsgPop.style.height=(popH-4).toString()+"px"; } else{ clearInterval(hide); MsgPop.style.display="none"; //隱藏DIV } } } window.onload=function(){ var oclose=document.getElementById("close"); var bt=document.getElementById("bt"); document.getElementById('winpop').style.height='0px'; setTimeout("tips_pop()",3000); oclose.onclick=function(){tips_pop()} bt.onclick=function(){tips_pop()} } </script> <body> <div id="silu"> <button id="bt">3秒后會在右下角自動彈出窗口,如果沒有彈出請點(diǎn)擊這個按鈕</button> </div> <div id="winpop"> <div class="title">您有新的短消息!<span class="close" id="close">X</span></div> <div class="con">1條未讀信息(</div> </div> </body> </html>
以上代碼實現(xiàn)了我們需要的功能,下面簡單介紹一下實現(xiàn)過程。
實現(xiàn)原理:
原理非常的簡單,下面分步做一下簡單的介紹:
1.讓窗口居于網(wǎng)頁的右下角:
實現(xiàn)代碼如下:
#winpop { width:200px; height:0px; position:absolute; right:0; bottom:0; border:1px solid #666; margin:0; padding:1px; overflow:hidden; display:none; }
以上代碼將windpop元素設(shè)置為絕對定位,尤其是將它的right和bottom屬性值設(shè)置為0,這樣就保證了它位于網(wǎng)頁的右下角,同時也將它的高度設(shè)置為0px,也就是說在默認(rèn)狀態(tài)下是隱藏的。
2.如何顯示和隱藏:
通過定時器函數(shù)setInterval()每隔指定時間調(diào)用一次changeH()函數(shù),此函數(shù)可以根據(jù)傳遞的值不斷的設(shè)置windpop的高度,這樣就實現(xiàn)了此窗口平滑出現(xiàn)和消失的效果。原理大體如上,這里就不多介紹了。
以上就是右下角彈出提示框的實現(xiàn)代碼,希望對大家的學(xué)習(xí)javascript程序設(shè)計有所幫助。
相關(guān)文章
微信小程序?qū)崿F(xiàn)動態(tài)渲染Markdown示例詳解
這篇文章主要為大家介紹了微信小程序?qū)崿F(xiàn)動態(tài)渲染Markdown示例詳解,有需要的朋友可以借鑒參考下,希望能夠有所幫助,祝大家多多進(jìn)步,早日升職加薪2023-08-08js對數(shù)組中的數(shù)字從小到大排序?qū)崿F(xiàn)代碼
對數(shù)組中的數(shù)字從小到大排序,很多時候需要用的多,需要的朋友可以參考下2012-09-09如何通過Proxy實現(xiàn)JSBridge模塊化封裝
這篇文章主要介紹了如何通過Proxy實現(xiàn)JSBridge模塊化封裝,文中通過示例代碼介紹的非常詳細(xì),對大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價值,需要的朋友可以參考下2020-10-10BootStrap實現(xiàn)手機(jī)端輪播圖左右滑動事件
用bootstrap做出的項目輪播圖在手機(jī)端不能滑動,為此找了好多插件、框架。但是都不能和bootstrap良好的結(jié)合。經(jīng)過一番折騰終于找到了解決方法,下面小編通過本文給大家簡單介紹下2016-10-10