<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>
<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>
本文介绍了一个简单的HTML页面,该页面使用JavaScript实现了一个图片元素的拖拽功能。通过监听dragstart和drag事件,使页面上的图片能够被鼠标拖动到任意位置。
2935

被折叠的 条评论
为什么被折叠?



