<html>
<head>
<style>
a{
position:relative;
}
</style>
<script type="text/javascript">
mouseover=true
function coordinates(event){
if (!moveMe){
alert("return");
return;
}
var event = event || window.event;
var eventId = event.srcElement?event.srcElement.id : event.target.id;
if (eventId =="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(event){
var event = event || window.event;
//alert(mouseover+"---"+event.button);
var eventButton = event.target?event.button:event.button-1;
//因为鼠标事件在不同浏览器下,取值是不同的,自己可以去查查看。
if (mouseover&&eventButton == 0){
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.onmouseup=mouseup;
document.onmousedown=coordinates;
</script>
</head>
<body>
<a id="moveMe" href = "http://www.baidu.com" >百度</a>
</body>
</html>
document.getElementById('moveMe').style.pixelLeft
就是这个东西,在火狐下无法取到值,也没有办法赋值。
哪位大神指点一下啊。
------最佳解决方案--------------------
赋值:
document.getElementById('moveMe').style.left= leftValue +"px";
取值:
var leftValue = parseInt(document.getElementById('moveMe').style.left,10);
------其他解决方案--------------------
pixelLeft这个东西firefox好像不行的,用left就好了啊
------其他解决方案--------------------
赋值是可以用的,但是取值不对,取不到值,我这边取值显示的内容为NaN,我用的火狐的版本是13.0.1
同时,我用笨方法做了一下,但是还有个问题,是在火狐下,在拖动之后,第一次放开鼠标左键时不会被触发,点右键的话,会触发的。就是onmouseup事件没有被执行。麻烦帮忙给看下情况呗,谢谢啦。
<html>
<head>
<style>
a{
position:relative;
}
</style>
<script type="text/javascript">
mouseover=true
function coordinates(event){
if (!moveMe){
alert("return");
return;
}
var event = event
------其他解决方案--------------------
window.event;
var eventId = event.srcElement?event.srcElement.id : event.target.id;
if (eventId =="moveMe"){
mouseover=true;
pleft=document.getElementById('moveMe').style.pixelLeft;
ptop=document.getElementById('moveMe').style.pixelTop;
if(!pleft){
pleft = event.pageX - 2;
}
if(!ptop){
ptop = event.pageY - 2;
}
xcoor=event.clientX;
ycoor=event.clientY;
document.onmousemove=moveImage
}
}
function moveImage(event){
var event = event