简单漂亮的js弹窗可自由拖拽且兼容大部分浏览器

简单漂亮的js弹窗 - 自由拖拽


代码如下:

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<title>简单漂亮的js弹窗 - 自由拖拽</title>
<script src="js/jquery-1.7.2.js"></script>
<script type="text/javascript">
//作者:zhao jinhan
//时间: 2013年10月22日
//邮箱:xb_zjh@126.com
function drag(o,s)
{
//drag(obj [,scroll]);
//obj:对象的id或对象本身;
//scroll(可选):对象是否随窗口拖动而滑动,默认为否

if (typeof o == "string") o = document.getElementById(o);
o.orig_x = parseInt(o.style.left) - document.body.scrollLeft;
o.orig_y = parseInt(o.style.top) - document.body.scrollTop;
o.orig_index = o.style.zIndex;

o.onmousedown = function(a)
{
this.style.zIndex = 10000;
var d=document;
if(!a)a=window.event;
var x = a.clientX+d.body.scrollLeft-o.offsetLeft;
var y = a.clientY+d.body.scrollTop-o.offsetTop;

d.ondragstart = "return false;"
d.onselectstart = "return false;"
d.onselect = "document.selection.empty();"

if(o.setCapture)
o.setCapture();
else if(window.captureEvents)
window.captureEvents(Event.MOUSEMOVE|Event.MOUSEUP);

d.onmousemove = function(a)
{
if(!a)a=window.event;
o.style.left = a.clientX+document.body.scrollLeft-x;
o.style.top = a.clientY+document.body.scrollTop-y;
o.orig_x = parseInt(o.style.left) - document.body.scrollLeft;
o.orig_y = parseInt(o.style.top) - document.body.scrollTop;
}

d.onmouseup = function()
{
if(o.releaseCapture)
o.releaseCapture();
else if(window.captureEvents)
window.captureEvents(Event.MOUSEMOVE|Event.MOUSEUP);
d.onmousemove = null;
d.onmouseup = null;
d.ondragstart = null;
d.onselectstart = null;
d.onselect = null;
o.style.cursor = "normal";
o.style.zIndex = o.orig_index;
}
}

if (s)
{
var orig_scroll = window.onscroll?window.onscroll:function (){};
window.onscroll = function ()
{
orig_scroll();
o.style.left = o.orig_x + document.body.scrollLeft;
o.style.top = o.orig_y + document.body.scrollTop;
}
}
}

var title = '提示标题';
var message='提示内容';
var TrueEvent='';
var CancelEvent='';
var CloseEvent='';
function dialogalert(title, message, TrueEvent, CancelEvent, CloseEvent) {
$("#divBackground").removeClass("hidden");
$("#divMaincontent").removeClass("hidden");

$("#alertTitle").html(title);
$("#alertContent").html(message);

$("#btnSure").click(function () {
$("#divBackground").addClass("hidden");
$("#divMaincontent").addClass("hidden");
$("#btnSure").unbind("click");
if (TrueEvent) {
//确认之后跳转url
window.location.href = TrueEvent;
}

}); //确定

$("#btnCancel").click(function () {
$("#divBackground").addClass("hidden");
$("#divMaincontent").addClass("hidden");
$("#btnCancel").unbind("click");
if (CancelEvent) {
//取消之后跳转url
window.location.href = CancelEvent;
}
});//取消

$("#btnClose").click(function () {
$("#divBackground").addClass("hidden");
$("#divMaincontent").addClass("hidden");
$("#btnClose").unbind("click");
if (CloseEvent) {
//关闭之后跳转url
window.location.href = CloseEvent;
}

});//X关闭
}

$(function(){
drag("divMaincontent");
dialogalert("弹窗标题","弹窗信息",'http://www.baidu.com/','http://www.icode100.com/','http://bbs.icode100.com/');
});
</script>
<style type="text/css">

body, p {
background: none repeat scroll 0 0 #FFFFFF;
color: #333333;
font-size: 12px;
margin: 0;
padding: 0;
}
.hidden { display:none}
.left { float:left }
.right { float:right }
#divMaincontent {
font-family: "微软雅黑","宋体",Microsoft Yahei,Tahoma,Arial,sans-serif;
font-size: 100%;
font-weight: normal;
position:absolute;
vertical-align: baseline;
}
#divMaincontent a { text-decoration:none; color:#333333;}
.blackf1 {
clear: both;
font-size: 0;
height: 12px;
line-height: 12px;
}
.fontcolorf1 {
color: #999999;
}
.pm_main {
border: 4px solid rgba(0, 0, 0, 0.1);
left: 40%;
position: fixed;
top: 40%;
width: 318px;
z-index: 10001;
}
.pm_tit1 {
background: url("images/dialog_blue.gif") repeat-x scroll 0 0 rgba(0, 0, 0, 0);
color: #FFFFFF;
height: 26px;
line-height: 26px;
padding: 0 1px;
text-indent: 16px;
width: 100%;
cursor:move;
}
.pm_tit1 a {
background: url("images/pm_bg.png") no-repeat scroll 0 -67px rgba(0, 0, 0, 0);
cursor: pointer;
height: 20px;
margin-right: 10px;
width: 20px;
}
.pm_tit1 a:hover {
background-position: 0 -90px;
}
.pm_con1 {
background: none repeat scroll 0 0 #CCCCCC;
max-height: 150px;
overflow-y: auto;
padding: 0 1px 1px;
width: 100%;
}
.pm_con2 {
background: none repeat scroll 0 0 #FFFFFF;
overflow: hidden;
padding: 16px 0;
width: 100%;
}
.pm_con2 p {
margin-left: 80px;
padding: 2px 0;
text-align: left;
}
.pm_con2 p.fontcolorf3 {
font-size: 14px;
font-weight: bold;
}
.pm_btn1 a, .pm_btn1 a:link, .pm_btn1 a:visited, .pm_btn1 a:hover, .pm_btn1 a:active {
background: url("images/pm_bg.png") no-repeat scroll 0 0 rgba(0, 0, 0, 0);
display: inline-block;
height: 28px;
line-height: 28px;
margin: 3px 40px 0 0;
text-align: center;
width: 53px;
}
.pm_btn1 a:hover {
background-position: 0 -35px;
color: #333333;
text-decoration: none;
}
</style>
</head>
<body>
<div class="pm_main hidden" id="divMaincontent">
<div class="pm_tit1"><span class="left">提示信息</span><a class="right" id="btnClose" href="javascript:void(0)"></a></div>
<div class="pm_con1">
<div class="pm_con2">
<p id="alertTitle">提示</p>
<p class="fontcolorf1" id="alertContent">今日秒杀已售罄</p>
<div class="blackf1"></div>
<div class="register_linef1"></div>
<p class="pm_btn1"><a id="btnSure" href="javascript:void(0)">确认</a><a id="btnCancel" href="javascript:void(0)">取消</a></p>
</div>
</div>
</div>
<script>

</script>
</body>
</html>

效果图片:
 
images/里面的图片:

dialog_blue.gif:
 
pm_bg.png
 
文件包下载:
http://www.jb51.net/jiaoben/112059.html

(0)

相关推荐

  • js点击弹出div层实现可拖曳的弹窗效果

    弹出层.弹窗效果+拖曳功能 *{ margin:0px; padding:0px;} body{ font-size:12px; font:Arial, Helvetica, sans-serif; margin:25PX 0PX; background:#eee;} .botton{ color:#F00; cursor:pointer;} .mybody{width:600px; margin:0 auto; height:1500px; border:1px solid #ccc; pad

  • js弹窗返回值详解(window.open方式)

    test.php 复制代码 代码如下: <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <meta http-

  • 超详细的JS弹出窗口代码大全

    如何利用网页弹出各种形式的窗口,我想大家大多都是知道些的,但那种多种多样的弹出式窗口是怎么搞出来的,我们今天就来学习一下: 1.弹启一个全屏窗口 代码如下: <html> <body http://www.jb51.net','我们','fullscreen');">; <b>www.jb51.net</b> </body> </html> 2.弹启一个被F11化后的窗口 代码如下: <html> <bod

  • Js控制弹窗实现在任意分辨率下居中显示

    贴代码 复制代码 代码如下: <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <meta http-equiv

  • JS自动适应的图片弹窗实例

    复制代码 代码如下: /************************************自动适应的图片弹窗*********************************/ var autoImg=function(argcs){/*调整图片大小,等比例缩放argcs['maxHeight']=>最大高度,argcs['maxWidth']=>最大宽度,argcs['height']=>图片高度,argcs['width']=>图片宽度*/                

  • 原生JS可拖动弹窗效果实例代码

    这个代码不是我原创的,只是最近想学自己做一个很漂亮的弹窗,自己本来是不会怎么写的,所以上网去找了下,感觉这个不错,很简单,很实用,入门很棒.我就改了下,使逻辑性和可读性更好. 原作者已不可考.感谢原作者,阿门. 复制代码 代码如下: <html>    <head>        <meta http-equiv="Content-Type"content="text/html; charset=gb2312"/>       

  • js弹窗代码 可以指定弹出间隔

    代码如下: 复制代码 代码如下: <SCRIPT LANGUAGE="javascript"> var Time=10; //设置每次弹出的相格的时间以秒为单位,现在是一天 function Set(){ var Then=new Date(); Then.setTime(Then.getTime()+Time*1000); document.cookie="netbei=1;expires="+Then.toGMTString(); } var coo

  • js退出弹窗代码集合

    var leave=true; function stbs() { if (leave) stb.DOM.Script.window.open('http://www.jb51.net/','_blank'); } [Ctrl+A 全选 注:如需引入外部Js需刷新才能执行] 支持 Windows XP SP2 xp sp3(即支持IE7)的超级弹退代码 使用说明: 1. 把SuperExitPopup.js这行 var popURL1 = 'http://tv.cnzz.cc'; 里面的网址改成

  • js实现弹窗插件功能实例代码分享

    目前测试下:支持IE6+ 火狐 谷歌游览器等. 先来看看此组件的基本配置项:如下: 复制代码 代码如下: this.config = { targetCls   :   '.clickElem',   // 点击元素 title:  '我是龙恩',      // 窗口标题 content     :  'text:<p style="width:100px;height:100px">我是龙</p>', //content            :  'img

  • js 右下角弹窗效果代码(IE only)

    右下角弹窗效果练习 function $(obj){ return document.getElementById(obj); } function pop(obj){ var h = parseInt($("popDiv").currentStyle.height); $("popDiv").style.height = (h + obj) + "px"; if(parseInt($("popDiv").style.heig

随机推荐