Chinaunix首页 | 论坛 | 博客

acc

  • 博客访问: 791738
  • 博文数量: 170
  • 博客积分: 7011
  • 博客等级: 少将
  • 技术积分: 1660
  • 用 户 组: 普通用户
  • 注册时间: 2006-07-31 12:02
文章分类

全部博文(170)

文章存档

2014年(7)

2010年(2)

2009年(62)

2008年(25)

2007年(67)

2006年(7)

我的朋友

分类: 系统运维

2009-08-24 17:18:11

<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312" />
<meta name="description"
content="Click here for a script that helps enable drag and drop on any image in the page!" />
<meta name="keywords" content="DHTML, drag and drop script, JavaScript, free" />
<title>Dynamic Drive DHTML Script- Dragable elements Script</title>
<link rel="stylesheet" type="text/css" href="../ddincludes/mainstyle.css" />
<style type="text/css">

.drag{
position:relative;
cursor:pointer;
z-index: 100;
}

</style>

<script type="text/javascript">

/***********************************************
* Drag and Drop Script: ?Dynamic Drive ()
* This notice MUST stay intact for legal use
* Visit / for this script and 100s more.
***********************************************/


var dragobject={
z: 0, x: 0, y: 0, offsetx : null, offsety : null, targetobj : null, dragapproved : 0,
initialize:function(){
document.onmousedown=this.drag
document.onmouseup=function(){this.dragapproved=0}
},
drag:function(e){
var evtobj=window.event? window.event : e
this.targetobj=window.event? event.srcElement : e.target
if (this.targetobj.className=="drag"){
this.dragapproved=1
if (isNaN(parseInt(this.targetobj.style.left))){this.targetobj.style.left=0}
if (isNaN(parseInt(this.targetobj.style.top))){this.targetobj.style.top=0}
this.offsetx=parseInt(this.targetobj.style.left)
this.offsety=parseInt(this.targetobj.style.top)
this.x=evtobj.clientX
this.y=evtobj.clientY
if (evtobj.preventDefault)
evtobj.preventDefault()
document.onmousemove=dragobject.moveit
}
},
moveit:function(e){
var evtobj=window.event? window.event : e
if (this.dragapproved==1){
this.targetobj.style.left=this.offsetx+evtobj.clientX-this.x+"px"
this.targetobj.style.top=this.offsety+evtobj.clientY-this.y+"px"
return false
}
}
}

dragobject.initialize()

</script>
</head>

<body>
<h1><b class="drag">这是可拖动的层!>
</h1>
<img src="" class="drag"><br>
</body>

</html>

阅读(438) | 评论(0) | 转发(0) |
给主人留下些什么吧!~~