This article explains the example code of the pop-up advertising information box in the lower right corner of the web page and shares it with everyone for your reference. The specific content is as follows
Rendering:
Specific code:
<!DOCTYPE html> <html> <head> <meta charset="gb2312"> <title>网页右下角的信息框</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);//将对象的高度转化为数字 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秒后会在右下角自动弹出窗口,如果没有弹出请点击这个按钮</button> </div> <div id="winpop"> <div class="title">您有新的短消息!<span class="close" id="close">X</span></div> <div class="con">1条未读信息(</div> </div> </body> </html>
The above code implements the functions we need. Here is a brief introduction to the implementation process.
Implementation principle:
The principle is very simple. Here is a brief step-by-step introduction:
1. Place the window in the lower right corner of the web page:
The implementation code is as follows:
#winpop { width:200px; height:0px; position:absolute; right:0; bottom:0; border:1px solid #666; margin:0; padding:1px; overflow:hidden; display:none; }
The above code sets the windpop element to absolute positioning, especially its right and bottom attribute values are set to 0, which ensures that it is located in the lower right corner of the web page, and also sets its height to 0px, that is Says it is hidden by default.
2. How to show and hide:
The changeH() function is called every specified time through the timer function setInterval(). This function can continuously set the height of the windpop according to the passed value, thus achieving the smooth appearance and disappearance of this window. . The principle is roughly the same as above, so I won’t introduce it much here.
The above is the implementation code for the pop-up prompt box in the lower right corner. I hope it will be helpful to everyone in learning javascript programming.