首页 > 语言 > JavaScript > 正文

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

2024-05-06 15:53:22
字体:
来源:转载
供稿:网友
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 src="http://www.vevb.com/uploads/allimg/131023/13024G344_0.gif?201392216943">

 
images/里面的图片:

dialog_blue.gif:

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

 
pm_bg.png

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

 
文件包下载:
发表评论 共有条评论
用户名: 密码:
验证码: 匿名发表

图片精选