Javascript简单实现可拖动的div
摘要:复制代码代码如下:varx;vary;function$(id){returndocument.getElementById(id)}fun...
复制代码 代码如下:
<html>
<head>
<script type="text/javascript">
var x;
var y;
function $(id)
{
return document.getElementById(id)
}
function mousedown()
{
x=event.clientX-$("px").style.pixelLeft;
y=event.clientY-$("px").style.pixelTop;
$("px").style.border="2px solid red";
$("px").onmousemove = mousemove;
}
function mouseup()
{
$("px").onmousemove = "";
$("px").style.border="";
}
function mousemove()
{
$("px").style.pixelLeft=event.clientX-x;
$("px").style.pixelTop=event.clientY-y;
}
</script>
</head>
<body>
<div id="px"
onmousedown="mousedown()" onmouseup="mouseup()" >
</div>
</body>
</html>
【Javascript简单实现可拖动的div】相关文章:
★ Javascript实现div的toggle效果实例分析
下一篇:
js简单实现让文本框内容逐个字的显示出来