div移动层精简示例(event事件兼容多浏览器)
2008-03-14 12:58
246 查看
<!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> New Document </title>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<meta http-equiv="Content-Language" content="zh-CN" />
<script language="JavaScript" type="text/javascript">
var drag_=false
var D=new Function('obj','return document.getElementById(obj);')
var oevent=new Function('e','if (!e) e = window.event;return e')
function Move_obj(obj){
var x,y;
D(obj).onmousedown=function(e){
drag_=true;
with(this){
style.position="absolute";var temp1=offsetLeft;var temp2=offsetTop;
x=oevent(e).clientX;y=oevent(e).clientY;
document.onmousemove=function(e){
if(!drag_)return false;
with(this){
style.left=temp1+oevent(e).clientX-x+"px";
style.top=temp2+oevent(e).clientY-y+"px";
}
}
}
document.onmouseup=new Function("drag_=false");
}
}
</script>
<body>
<div id="test" style="background-color:#0099CC;width:200px;height:100px;border:1px #000 solid;" onmouseover='Move_obj("test")'>鼠标过来点击拖动层</div>
</body>
</html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title> New Document </title>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<meta http-equiv="Content-Language" content="zh-CN" />
<script language="JavaScript" type="text/javascript">
var drag_=false
var D=new Function('obj','return document.getElementById(obj);')
var oevent=new Function('e','if (!e) e = window.event;return e')
function Move_obj(obj){
var x,y;
D(obj).onmousedown=function(e){
drag_=true;
with(this){
style.position="absolute";var temp1=offsetLeft;var temp2=offsetTop;
x=oevent(e).clientX;y=oevent(e).clientY;
document.onmousemove=function(e){
if(!drag_)return false;
with(this){
style.left=temp1+oevent(e).clientX-x+"px";
style.top=temp2+oevent(e).clientY-y+"px";
}
}
}
document.onmouseup=new Function("drag_=false");
}
}
</script>
<body>
<div id="test" style="background-color:#0099CC;width:200px;height:100px;border:1px #000 solid;" onmouseover='Move_obj("test")'>鼠标过来点击拖动层</div>
</body>
</html>
相关文章推荐
- div移动层精简示例(event事件兼容多浏览器)
- event 事件 键盘控制div移动
- 第3课 02 JS中级课程-event-事件(跟随鼠标移动的div)
- 可移动层 div 兼容多浏览器 兼容firefox
- (浏览器兼容)键盘事件兼容写法e=window.event||e;键盘检测兼容写法key = e.keyCode || e.which || e.charCode;
- html5移动设备浏览器触屏事件兼容处理
- JS添加/绑定事件监听函数并传参数attachEvent和addEventListener兼容个浏览器
- 可以移动的层(Div)兼容IE和firefox浏览器
- 兼容firefox,ie,谷歌,阻止浏览器冒泡事件,Firefox不支持event解决方法
- javascript event事件再次封装了,兼容大多数浏览器
- firefox浏览器兼容event事件方法
- 关于浏览器兼容问题:获取div的值
- DIV+CSS必须考虑的浏览器兼容的技巧
- 兼容的IE、FireFox的event事件[收藏]
- div+CSS浏览器兼容问题整理(IE6.0、IE7.0 ,ie8 , FireFox...)
- js的window.onscroll事件兼容各大浏览器
- div+css 实现无js滚动 兼容各大浏览器!!!
- DIV+CSS布局:多浏览器兼容 指定CSS的最小高度
- 具有跨浏览器兼容的事件处理javascript脚本
- DIV JS CSS 轻量级弹出层 兼容各浏览器