ITeye博客

JavaScript图片拖动效果(ondragstart和ondrag)

piperzero · 2013-06-13 18:19 · Markdown

<html>
<head>
<style type='text/css'>
.wen p{
text-align:left;
margin:15px 0 0 5px;
}
</style>
<script type='text/javascript'>
var xx=0,yy=0;
function movea(v){
xx=event.x-v.offsetLeft;
yy=event.y-v.offsetTop;
}
function moveb(v){
v.style.left=event.x-xx;
v.style.top=event.y-yy;
}
</script>
</head>
<body>
<img id='img' src='01.jpg' style='position:absolute'
ondragstart='movea(this);' ondrag='moveb(this);'>
</body>
</html>


<wbr></wbr>

评论(0)

暂无评论。

评论功能维护中,当前仅展示历史评论。