<script>
var oImg = document.querySelector('img');
drag(oImg);
function drag(obj){
obj.onmousedown = function (ev) {
var ev = ev || window.event;
var shortx = ev.offsetX;
var shorty = ev.offsetY;
document.onmousemove = function (ev) {
var ev = ev || window.event;
obj.style.left = ev.clientX - shortx + 'px';
obj.style.top = ev.clientY - shorty + 'px';
}
document.onmouseup = function () {
document.onmousemove = null;
document.onmouseup = null;
};
return false;
}
}
<style>
img {
width: 300px;
position: absolute;
}
</style>
</script>
拖拽
最新推荐文章于 2022-10-17 21:15:31 发布