Home > Article > Web Front-end > js to imitate NetEase click pop-up prompts and background darkening effect_javascript skills
The example in this article describes how js can imitate NetEase click pop-up prompts and darken the background effect. Share it with everyone for your reference. The details are as follows:
The pop-up prompt here is imitated by NetEase, with the background darkening prompt layer effect, rounded corners, beautiful and concise, and a little too much code.
The operation effect is as shown below:
The online demo address is as follows:
http://demo.jb51.net/js/2015/js-sina-dialog-bgcolor-codes/
The specific code is as follows:
<html> <head> <title>点击弹出提示,背景变暗</title> <script> function msg(info){ var p=document.createElement("DIV"); if (!info) var info='<a href="#" target="_blank" rel="external">欢迎光临</a>'; p.id="p"; p.style.position="absolute"; p.style.width=document.body.scrollWidth; p.style.height=(document.body.offsetHeight>document.body.scrollHeight)?'100%':document.body.scrollHeight; p.style.zIndex='998'; p.style.top='0px'; p.style.left='0%'; p.style.backgroundColor="gray"; p.style.opacity='0.5'; p.style.filter="alpha(opacity=80)"; document.body.appendChild(p); var p1=document.createElement("DIV"); var top=parseInt(parseInt(document.body.scrollHeight)*0.25)+document.body.scrollTop; p1.style.position="absolute"; p1.style.width="300px"; p1.id="p1"; var left=Math.ceil(((document.body.scrollWidth)-parseInt(p1.style.width.replace('px','')))/2)+document.body.scrollLeft; p1.style.height="200px"; p1.style.zIndex='999'; p1.style.top=top+'px'; p1.style.left=left+'px'; p1.style.border="0px solid red"; var html=""; html+="<center>" html+="<div class='p3' style='height:1px;overflow:hidden;background:red;width:294px;border-left:1px solid red;border-right:1px solid red;'></div>" html+="<div class='p2' style='height:1px;overflow:hidden;background:red;width:296px;border-left:1px solid red;border-right:1px solid red;'></div>" html+="<div class='p2' style='height:1px;overflow:hidden;background:red;width:298px;border-left:1px solid red;border-right:1px solid red;'></div>" html+="<div class='p1' style='height:20px;overflow:hidden;background:red;width:300px;border-left:1px solid red;border-right:1px solid red;color:#fff;font-size:9pt;font-weight:bold;text-align:left;'> ⊙ 友情提示:</div>" html+="<div id='c' style='height:150px;width:300px;background-color:#FEEACB;overflow:hidden;border-left:1px solid red;border-right:1px solid red;padding-top:40px;font-size:9pt;'>"+info+"<br><br><br>[ <a href='javascript:this.cancle()'> 关闭</a> ]</div>" html+="<div class='p1' style='height:1px;overflow:hidden;background:#FEEACB;width:298px;border-left:1px solid red;border-right:1px solid red;'></div>" html+="<div class='p2' style='height:1px;overflow:hidden;background:#FEEACB;width:296px;border-left:1px solid red;border-right:1px solid red;'></div>" html+="<div class='p3' style='height:1px;overflow:hidden;background:red;width:294px;border-left:1px solid red;border-right:1px solid red'></div>" html+="</center>" document.body.appendChild(p1); p1.innerHTML=html; var arr=document.getElementsByTagName("select"); var i=0; while(i<arr.length){ arr[i].style.visibility='hidden'; i++; } this.cancle=function(){ document.body.removeChild(document.getElementById('p')); document.body.removeChild(document.getElementById('p1')); var arr=document.getElementsByTagName("select"); var i=0; while(i<arr.length){ arr[i].style.visibility='visible'; i++; } } } </script> </head> <body> <input value='点击弹出提示' type='button' onClick='msg()' /> </body> </html>
I hope this article will be helpful to everyone’s JavaScript programming design.