图片在div中任意拖动
在网页中,实现一张图片在一个层内任意拖动,图片不能超过层的区域,高手帮帮忙,最好在VS中用JS实现,谢谢!!!...
在网页中,实现一张图片在一个层内任意拖动,图片不能超过层的区域,高手帮帮忙,最好在VS中用JS实现,谢谢!!!
展开
2013-04-17
展开全部
<html>
<head>
<script language=javascript>
function imgMove()
{
//if the left button was not pressed,return
if(window.event.button!= 1)
{
return 0;
}
//get the new position
with(window.event.srcElement.style)
{
pixelLeft = window.event.x-236/2-document.all.imgDiv.offsetLeft;
pixelTop = window.event.y-118/2-document.all.imgDiv.offsetTop;
}
window.event.returnValue=false;
}
</script>
</head>
<body>
<div Style="position:relative" ID="imgDiv">
<img src="20080105039.jpg" id="img2" Style="CONTAINER:positioned;position:absolute;
top:60px;left:60px;236px;height:118px;" onMouseMove=imgMove()>
</div>
</body>
</html>
你把<img src="20080105039.jpg" id="img2" 换成你的图片就OK了
<head>
<script language=javascript>
function imgMove()
{
//if the left button was not pressed,return
if(window.event.button!= 1)
{
return 0;
}
//get the new position
with(window.event.srcElement.style)
{
pixelLeft = window.event.x-236/2-document.all.imgDiv.offsetLeft;
pixelTop = window.event.y-118/2-document.all.imgDiv.offsetTop;
}
window.event.returnValue=false;
}
</script>
</head>
<body>
<div Style="position:relative" ID="imgDiv">
<img src="20080105039.jpg" id="img2" Style="CONTAINER:positioned;position:absolute;
top:60px;left:60px;236px;height:118px;" onMouseMove=imgMove()>
</div>
</body>
</html>
你把<img src="20080105039.jpg" id="img2" 换成你的图片就OK了
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询