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

帮忙看个监听鼠标点击和移动的程序
我编写了监听点击鼠标松开的事件,但为什么没有执行,代码:
var firx; //这是定义的鼠标点击时此点的坐标
var firy; //这是定义的鼠标点击时此点的坐标
var ptx;  
var pty;
var lockmouse=false;
window.onload=function()
{
var obj = document.getElementById("imgmap");//找到对象
  //s设置鼠标单击监听函数
obj.onmousedown=function(e)
{
lockmouse=true;
oEvent=e||event;
  obj.mouseStart={};
obj.mouseStart.x=oEvent.clientX;
obj.mouseStart.y=oEvent.clientY;
firx=obj.mouseStart.x-10;
firy=obj.mouseStart.y-15;
}
obj.onmousemove=function(e) // 这是监听鼠标移动
 {
 
  oEvent=e||event;  
var endx=oEvent.clientX-10;
var endy=oEvent.clientY-15;
if(lockmouse==true)
{
  if(toolType == 1 || toolType == 2)
{
}
else if(toolType==3)
{
var dxMove,dyMove;
dxMove = endx - firx;
dyMove = endy - firy;
}
  }
 }
obj.onmouseup=function(e)
{
oEvent=e||event;
  var endx = oEvent.clientX - 10;
var endy = oEvent.clientY - 15;
if(lockmouse==true)
{
  if(toolType==0)
{
}
if(toolType==1)
{
document.all.imgmap.src="maptest?toolType=1" + "&ptx=" + firx + "&pty=" + firy;

}
if(toolType==2)
document.all.imgmap.src="maptest?toolType=2" + "&ptx=" + firx + "&pty=" + firy;

}
if(toolType == 3)
{
var dxMove=0.0,dyMove=0.0;
var centerX=0,centerY=0;
centerX = 410; //现在的这个图片的中心
centerY = 265;  
dxMove = endx - firx;
dyMove = endy - firy;
centerX =centerX - dxMove;
centerY =centerY - dyMove;
document.all.imgmap.src="maptest?toolType=3" + "&ptx=" + centerX + "&pty=" + centerY;
}
}
lockmouse=false;

}
我认为当你单击鼠标没有松开时lockmouse=true;然后我拖动鼠标,(当toolType == 3)鼠标松开时,应该执行document.all.imgmap.src="maptest?toolType=3" + "&ptx=" + centerX + "&pty=" + centerY;这一句,但是并没有执行,是哪里错了,再就是怎么能让单击图片时,拖动鼠标你的图片也跟着移动,谢谢解答。


------解决方案--------------------
tooltype哪来的?