拖动层 拖动div 封装js 貌似不兼容FF,郁闷

原文发布时间为:2009-12-02 —— 来源于本人的百度文章 [由搬家工具导入]

<!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> <title>拖动效果函数演示 by http://hi.baidu.com/handboy </title>
<style>
body
{
font-size:12px;
color:#333333;
border : 0px solid blue;
}
div
{
position : absolute;
background-color : #c3d9ff;
margin : 0px;
padding : 5px;
border : 0px;
width : 100px;
height:100px;
}
</style>
</head>
<body>
<script type="text/javascript">
function drag(o,s)
{
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.cursor = "move";
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;
//author: hi.baidu.com/handboy
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;
}
}
}
</script>

<div id="div1" style="left:10px;top:10px;">div1:我可以被拖动 </div>
<div id="div2" style="left:120px;top:10px;background-color : #f3d9ff">div2:来拖我呀 </div>
<div id="div3" style="left:230px;top:10px;background-color : #c3ffff">div3:我随便你拖 </div>
<div id="div4" style="left:10px;top:120px;background-color : #c3d944">div4:我可以随窗口滑动,把我拖到最下面,然后滚动网页看看 </div>
<div id="div5" style="left:120px;top:120px;background-color : #f3d944">作者: Handboy
<a href=http://www.longbill.cn target=_blank>hi.baidu.com/handboy </a>
</div>
<div id="div6" style="left:230px;top:120px;background-color : #e3f944;width:200px;">参数说明:

drag(obj [,scroll]);

obj:对象的id或对象本身;

scroll(可选):对象是否随窗口拖动而滑动,默认为否

鼠标右键查看源代码
</div>

<script type="text/javascript">
drag("div1");
drag("div2");
drag("div3");
drag("div4",1);
drag("div5",1);
drag("div6",1);

</script>

</body>
</html>

时间: 2024-08-07 23:22:02

拖动层 拖动div 封装js 貌似不兼容FF,郁闷的相关文章

iGoogle的模块拖动层拖动

<!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="Content-Typ

js拖动层

模仿网易彩票网(http://caipiao.163.com/)的登陆框自己做了一个拖动层,不过有点小问题——在谷歌浏览拖动的时候鼠标状态变成了文字状态(cursor:text;) 1 <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> 2 <html xml

JavaScript:Div层拖动效果

Div层拖动效果图: 实现: CSS: <style> div { position:relative; } </style> JS: <script type="text/javascript"> var mouseover=true var xcoor; var ycoor; function coordinates() { if (event.srcElement.id.indexOf("wishbroad") == 0)

jQuery制作div板块拖动层排序

html结构: <!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="

拖动鼠标改变div层的大小宽度

<html> <head> <title>拖动鼠标改变div层的大小宽度-石家庄色彩顾问-亿诚</title> <meta content="text/html; charset=gb2312" http-equiv="Content-Type"> <style> { box-sizing: border-box; moz-box-sizing: border-box } #testDiv {

完整的网页浮动层拖动实例代码

一个供学习不错的网页拖动层,具有丰富的层拖动设置功能,比如可设置拖动的范围.垂直.水平方向拖动,是否透明显示层等,运用JS和CSS等实现的HTML层拖动网页,代码完整:前端框架资源分享 .代码   <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html

【类库】私房干货.Net数据层方法的封装

[类库]私房干货.Net数据层方法的封装 作者:白宁超 时间:2016年3月5日22:51:47 摘要:继上篇<Oracle手边常用70则脚本知识汇总>文章的发表,引起很多朋友关注.便促使笔者收集整理此文.本文主要针是对微软技术对数据库(下文案例采用的)操作时,调用执行方法的封装,这也是数年逐渐学习.吸收.实践.完成的一个类库.其中不免有不合理之处,亦或是不符合个别读者的使用习惯.在此,共享此文,权当互相学习.(本文原创,转载注明出处:私房干货.Net数据层方法的封装) 1 概述 本文分以下几

封装js千分位加逗号和删除逗号

原文:封装js千分位加逗号和删除逗号 //封装js千分位加逗号和删除逗号 alert( format(2545678754.020001) ) //2,545,678,754.03 alert( format(-2545678754.020001) ) //-2,545,678,754.02 alert( format(2545678754.000000000009) ); //当值很长的时候会出现数字被截取的问题 alert( delformat('2,545,678,754.03') );

DIV+CSS+JS仿Select下拉表单网页特效源代码下载

DIV+CSS+JS仿Select下拉表单 原文:DIV+CSS+JS仿Select下拉表单网页特效源代码下载 源代码下载地址:http://www.zuidaima.com/share/1550463331830784.htm <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"> <