Simple and beautiful js pop-up window - free drag and drop Copy code The code is as follows: Simple and beautiful js pop-up window - free drag < script src="js/jquery-1.7.2.js"> <br>//Author: zhao jinhan <br>// Time: October 22, 2013<br>//Email: xb_zjh@126.com <br>function drag(o,s) <br>{ <br>//drag(obj [,scroll]); <br>//obj: the id of the object or the object itself; <br>//scroll (optional): whether the object slides as the window is dragged, the default is no <br><br>if (typeof o == "string" ) o = document.getElementById(o); <br>o.orig_x = parseInt(o.style.left) - document.body.scrollLeft; <br>o.orig_y = parseInt(o.style.top) - document. body.scrollTop; <br>o.orig_index = o.style.zIndex; <br><br>o.onmousedown = function(a) <br>{ <br>this.style.zIndex = 10000; <br>var d=document; <br>if(!a)a=window.event; <br>var x = a.clientX d.body.scrollLeft-o.offsetLeft; <br>var y = a.clientY d.body. scrollTop-o.offsetTop; <br><br>d.ondragstart = "return false;" <br>d.onselectstart = "return false;" <br>d.onselect = "document.selection.empty();" <br><br>if(o.setCapture) <br>o.setCapture(); <br>else if(window.captureEvents) <br>window.captureEvents(Event.MOUSEMOVE|Event.MOUSEUP); <br> <br>d.onmousemove = function(a) <br>{ <br>if(!a)a=window.event; <br>o.style.left = a.clientX document.body.scrollLeft-x; <br>o.style.top = a.clientY document.body.scrollTop-y; <br>o.orig_x = parseInt(o.style.left) - document.body.scrollLeft; <br>o.orig_y = parseInt( o.style.top) - document.body.scrollTop; <br>} <br><br>d.onmouseup = function() <br>{ <br>if(o.releaseCapture) <br>o.releaseCapture( ); <br>else if(window.captureEvents) <br>window.captureEvents(Event.MOUSEMOVE|Event.MOUSEUP); <br>d.onmousemove = null; <br>d.onmouseup = null; <br>d .ondragstart = null; <br>d.onselectstart = null; <br>d.onselect = null; <br>o.style.cursor = "normal"; <br>o.style.zIndex = o.orig_index; <br>} <br>} <br><br>if (s) <br>{ <br>var orig_scroll = window.onscroll?window.onscroll:function (){}; <br>window.onscroll = function ( ) <br>{ <br>orig_scroll(); <br>o.style.left = o.orig_x document.body.scrollLeft; <br>o.style.top = o.orig_y document.body.scrollTop; <br>} <br>} <br>} <br><br>var title = 'Prompt title'; <br>var message='Prompt content'; <br>var TrueEvent=''; <br>var CancelEvent= ''; <br>var CloseEvent=''; <br>function dialogalert(title, message, TrueEvent, CancelEvent, CloseEvent) { <br>$("#divBackground").removeClass("hidden"); <br> $("#divMaincontent").removeClass("hidden"); <br><br>$("#alertTitle").html(title); <br>$("#alertContent").html(message); <br><br>$("#btnSure").click(function () { <br>$("#divBackground").addClass("hidden"); <br>$("#divMaincontent").addClass ("hidden"); <br>$("#btnSure").unbind("click"); <br>if (TrueEvent) { <br>//Jump to url after confirmation <br>window.location.href = TrueEvent; <br>} <br><br>}); //OK<br><br>$("#btnCancel").click(function () { <br>$("#divBackground"). addClass("hidden"); <br>$("#divMaincontent").addClass("hidden"); <br>$("#btnCancel").unbind("click"); <br>if (CancelEvent) { <br>//Jump to url after cancellation <br>window.location.href = CancelEvent; <br>} <br>});//Cancel<br><br>$("#btnClose").click (function () { <br>$("#divBackground").addClass("hidden"); <br>$("#divMaincontent").addClass("hidden"); <br>$("#btnClose" ).unbind("click"); <br>if (CloseEvent) { <br>//Jump url after closing <br>window.location.href = CloseEvent; <br>} <br><br>}) ;// ://www.baidu.com/','http://www.icode100.com/','http://bbs.icode100.com/'); <br>}); <br></ script> <br><style type="text/css"> <br><br>body, p { <br>background: none repeat scroll 0 0 #FFFFFF; <br>color: #333333; <br>font-size: 12px; <br>margin: 0; <br>padding: 0; <br>} <br>.hidden { display:none} <br>.left { float:left } <br>.right { float:right } <br>#divMaincontent { <br>font-family: "Microsoft Yahei","宋体",Microsoft Yahei,Tahoma,Arial,sans-serif; <br>font-size: 100%; <br>font-weight: normal; <br>position:absolute; <br>vertical-align: baseline; <br>} <br>#divMaincontent a { text-decoration:none; color:#333333;} <br> .blackf1 { <br>clear: both; <br>font-size: 0; <br>height: 12px; <br>line-height: 12px; <br>} <br>.fontcolorf1 { <br>color: #999999; <br>} <br>.pm_main { <br>border: 4px solid rgba(0, 0, 0, 0.1); <br>left: 40%; <br>position: fixed; <br>top : 40%; <br>width: 318px; <br>z-index: 10001; <br>} <br>.pm_tit1 { <br>background: url("images/dialog_blue.gif") repeat-x scroll 0 0 rgba(0, 0, 0, 0); <br>color: #FFFFFF; <br>height: 26px; <br>line-height: 26px; <br>padding: 0 1px; <br>text-indent : 16px; <br>width: 100%; <br>cursor:move; <br>}<br>.pm_tit1 a { <br>background: url("images/pm_bg.png") no-repeat scroll 0 -67px rgba(0, 0, 0, 0); <br>cursor: pointer; <br>height: 20px; <br>margin-right: 10px; <br>width: 20px; <br>} <br>.pm_tit1 a:hover { <br>background-position: 0 -90px; <br>} <br>.pm_con1 { <br>background: none repeat scroll 0 0 #CCCCCC; <br>max-height: 150px; <br>overflow-y: auto; <br>padding: 0 1px 1px; <br>width: 100%; <br>} <br>.pm_con2 { <br>background: none repeat scroll 0 0 #FFFFFF; <br>overflow: hidden; <br>padding: 16px 0; <br>width: 100%; <br>} <br>.pm_con2 p { <br>margin-left: 80px; <br>padding: 2px 0; <br>text-align: left; <br>} <br>.pm_con2 p.fontcolorf3 { <br>font-size: 14px; <br>font-weight: bold; <br>} <br>.pm_btn1 a, .pm_btn1 a:link, .pm_btn1 a:visited, .pm_btn1 a:hover, .pm_btn1 a:active { <br>background: url("images/pm_bg.png") no-repeat scroll 0 0 rgba(0, 0, 0, 0); <br>display: inline-block; <br>height: 28px; <br>line-height: 28px; <br>margin: 3px 40px 0 0; <br>text-align: center; <br>width: 53px; <br>} <br>.pm_btn1 a:hover { <br>background-position: 0 -35px; <br>color: #333333; <br>text-decoration: none; <br>} <br></style> <br></head> <br><body> <br><div class="pm_main hidden" id="divMaincontent"> <br><div class="pm_tit1"><span class="left">提示信息</span><a class="right" id="btnClose" href="javascript:void(0)"></a></div> <br><div class="pm_con1"> <br><div class="pm_con2"> <br><p id="alertTitle">提示</p> <br><p class="fontcolorf1" id="alertContent">今日秒杀已售罄</p> <br><div class="blackf1"></div> <br><div class="register_linef1"></div> <br><p class="pm_btn1"><a id="btnSure" href="javascript:void(0)">确认</a><a id="btnCancel" href="javascript:void(0)">取消</a></p> <br></div> <br></div> <br></div> <br><script> <br><br> 效果图片: images/里面的图片: dialog_blue.gif: pm_bg.png 文件包下载: http://www.jb51.net/jiaoben/112059.html