JavaScript Implementation click the button to pop a window to close the same time Web page background dimmed

Source: Internet
Author: User
Tags border color

The example of this article tells the JavaScript implementation click button to pop a window to close the layer and the background of the Web page dimmed. Share to everyone for your reference. The specific analysis is as follows:

Here click the button, pop-up a closed layer window, with the background of the Web page dimmed, QQ site will often see the effect of QQ login, and this very similar, code snippets based on JavaScript, according to your situation, and sometimes the use of CSS to complete this function.

?

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26-27--28 29---30 31--32 33 34 35 36 37 38-39 40 41 42 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 5 86 87 88 <html> <head> <meta http-equiv= "Content-type" content= "text/html; Charset=utf-8 "/> <title> eject a layer, page dimmed </title> <script language=" JavaScript "> Function Alertwin ( Title, MSG, W, h) {var titleheight = "23px";//Window caption height var bordercolor = "#336699";//Prompt window border color var titlecolor = "#FFFFFF "; Window title color var titlebgcolor = "#336699"; Window title background color var bgcolor = "#FFFFFF"; The background color of the hint content var iwidth = document.documentElement.clientWidth; var iheight = document.documentElement.clientHeight; var bgobj = document.createelement ("div"); BgObj.style.cssText = "Position:absolute;left:0px;top:0px;width:" +iwidth+ "Px;height:" +math.max ( Document.body.clientHeight, iheight) + "Px;filter:alpha (opacity=30); Opacity:0.3;background-color: #000000; z-index : 101; "; Document.body.appendChild (Bgobj); var msgobj=document.createelement ("div"); MsgObj.style.cssText = "position:absolute;font:11px ' song Body"; Top: "+ (iheight-h)/2+" Px;left: "+ (IWIDTH-W)/2+" Px;width: "+ w+ "Px;height:" +h+ "Px;text-align:center;border:1px solid "+bordercolor+"; Background-color: "+bgcolor+";p adding:1px;line-height:22px;z-index:102; "; Document.body.appendChild (Msgobj); var table = document.createelement ("table"); Msgobj.appendchild (table); Table.style.cssText = "margin:0px;border:0px;padding:0px;"; table.cellspacing = 0; var tr = Table.insertrow (-1); var titlebar = Tr.insertcell (-1); TitleBar.style.cssText = "Width:100%;height:" +titleheight+ "Px;text-align:left;padding:3px;margin:0px;font:bold 13px ' song body '; color: "+titlecolor+"; border:1px solid "+ bordercolor +"; Cursor:move;background-color: "+ titlebgcolor; TitleBar.style.paddingLeft = "10px"; titlebar.innerhtml = title; var MoveX = 0; var movey = 0; var movetop = 0; var moveLeft = 0; var moveable = false; var docmousemoveevent = Document.onmousemove; var docmouseupevent = Document.onmouseup; Titlebar.onmousedown = function () {var evt = getEvent (); moveable = true; MoveX = evt.clientx; movey = Evt.clienty; movet op = parseint (msgObj.style.top); MoveLeft = parseint (msGObj.style.left); Document.onmousemove = function () {if (moveable) {var evt = getEvent (); var x = MoveLeft + Evt.clientx-movex; var y = Movetop + Evt.clienty-movey; if (x > 0 && (x + W < iwidth) && y > 0 && (y + H < iheight)) {msgObj.style.left = X + "px"; MsgObj.style.top = y + "px"; } } }; Document.onmouseup = function () {if (moveable) {document.onmousemove = docmousemoveevent; document.onmouseup = DocMouse Upevent; moveable = false; MoveX = 0; Movey = 0; movetop = 0; MoveLeft = 0; } }; var closebtn = Tr.insertcell (-1); CloseBtn.style.cssText = "Cursor:pointer; Padding:2px;background-color: "+ titlebgcolor; closebtn.innerhtml = "<span style= ' font-size:15pt;" Color: "+titlecolor+"; >x</span> "; Closebtn.onclick = function () {document.body.removeChild (bgobj); Document.body.removeChild (msgobj);} var msgBox = Table.insertrow ( -1). InsertCell (-1); MsgBox.style.cssText = "font:10pt ' song Body ';"; Msgbox.colspan = 2; msgbox.innerhtml = msg;Get event object for compatibility with IE and Firefox function getEvent () {return window.event | | arguments.callee.caller.arguments[0];} </script> </head> <body> <input type= "button" value= "dot Here" onclick= "Alertwin (' click Popup to close the Layer window, Web page dimmed ', 290,208); "/> </body> </html>

The

wants this article to help you with your JavaScript programming.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.