日期:2014-05-16  浏览次数:20349 次

这种功能怎么实现啊,求教
本帖最后由 asdfg123_ 于 2012-11-25 13:35:25 编辑
要用到超链接拖动的功能,就像这个http://www.60site.com/的超链接可以拖动一样,请问这原理怎么实现的......最好能有代码参考
------解决方案--------------------
<html>
<head>
<style>
a{
position:relative;
}
</style>
<script type="text/javascript">
mouseover=true
function coordinates()
{
if (!moveMe)
{
return
}
if (event.srcElement.id=="moveMe")
{
mouseover=true
pleft=document.getElementById('moveMe').style.pixelLeft
ptop=document.getElementById('moveMe').style.pixelTop
xcoor=event.clientX
ycoor=event.clientY

document.onmousemove=moveImage
}
}

function moveImage()
{
if (mouseover&&event.button==1)
{
document.getElementById('moveMe').style.pixelLeft=pleft+event.clientX-xcoor
document.getElementById('moveMe').style.pixelTop=ptop+event.clientY-ycoor
return false
}
}

function mouseup()
{
mouseover=false;
}
document.onmousedown=coordinates
document.onmouseup=mouseup
</script>
</head>
<body>
<a  id="moveMe" href = "http://www.baidu.com" >百度</a>
</body>
</html>


是类似这样吧。。
------解决方案--------------------
拖动之前加在js中加this._Handle.setCapture();拖动停止时加this._Handle.releaseCapture();参考
由于A标签是内嵌标签,即使是加display:inline-block;样式在某些游览器下还是不能被拖动的。