如何用javascript实现div在页面上拖动的效果?

来源:百度知道 编辑:UC知道 时间:2024/09/28 08:31:02
非常感谢!!!

<html>
<head><title>拖动效果函数演示 by Longbill.cn</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>
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