国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁(yè) > 編程 > JavaScript > 正文

js右下角彈出提示框示例代碼

2019-11-20 10:49:22
字體:
來(lái)源:轉(zhuǎn)載
供稿:網(wǎng)友

本文實(shí)例講解了網(wǎng)頁(yè)右下角彈出廣告信息框?qū)嵗a,分享給大家供大家參考,具體內(nèi)容如下

效果圖:

具體代碼:

<!DOCTYPE html><html><head><meta charset="gb2312"><title>網(wǎng)頁(yè)右下角的信息框</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);//將對(duì)象的高度轉(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秒后會(huì)在右下角自動(dòng)彈出窗口,如果沒(méi)有彈出請(qǐng)點(diǎn)擊這個(gè)按鈕</button></div><div id="winpop"> <div class="title">您有新的短消息!<span class="close" id="close">X</span></div> <div class="con">1條未讀信息(</div></div></body></html>

以上代碼實(shí)現(xiàn)了我們需要的功能,下面簡(jiǎn)單介紹一下實(shí)現(xiàn)過(guò)程。
實(shí)現(xiàn)原理:
原理非常的簡(jiǎn)單,下面分步做一下簡(jiǎn)單的介紹:
1.讓窗口居于網(wǎng)頁(yè)的右下角:
實(shí)現(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è)置為絕對(duì)定位,尤其是將它的right和bottom屬性值設(shè)置為0,這樣就保證了它位于網(wǎng)頁(yè)的右下角,同時(shí)也將它的高度設(shè)置為0px,也就是說(shuō)在默認(rèn)狀態(tài)下是隱藏的。
2.如何顯示和隱藏:
通過(guò)定時(shí)器函數(shù)setInterval()每隔指定時(shí)間調(diào)用一次changeH()函數(shù),此函數(shù)可以根據(jù)傳遞的值不斷的設(shè)置windpop的高度,這樣就實(shí)現(xiàn)了此窗口平滑出現(xiàn)和消失的效果。原理大體如上,這里就不多介紹了。

以上就是右下角彈出提示框的實(shí)現(xiàn)代碼,希望對(duì)大家的學(xué)習(xí)javascript程序設(shè)計(jì)有所幫助。

發(fā)表評(píng)論 共有條評(píng)論
用戶(hù)名: 密碼:
驗(yàn)證碼: 匿名發(fā)表
主站蜘蛛池模板: 招远市| 彰化县| 自治县| 九龙城区| 大邑县| 遂溪县| 饶平县| 巴中市| 巴塘县| 银川市| 繁昌县| 中山市| 都江堰市| 石泉县| 五家渠市| 天祝| 浑源县| 乌拉特前旗| 板桥市| 西昌市| 宜昌市| 张家港市| 全州县| 郑州市| 松原市| 察雅县| 杭州市| 建瓯市| 大邑县| 天柱县| 武清区| 都昌县| 眉山市| 花垣县| 仁寿县| 东阿县| 日喀则市| 南部县| 肥西县| 沅江市| 余庆县|