【发布时间】:2015-05-02 00:29:48
【问题描述】:
我对 Javascript 非常陌生,需要一些帮助。我在画布中显示一个图像,并且我希望在拖动该图像时获得不同的事件:例如,使用鼠标中键拖动时缩放,使用鼠标右键拖动图像时进行平移。 .. 使用 Chrome 时,我能够捕捉到这些事件,但是当我使用 Firefox 尝试时,我的代码不起作用。你能给我一些帮助吗?这是我的代码:
isDragging = false;
// Mousedown : isDragging is true and get mouse position
$("#s1").bind('mousedown', function(event)
{
isDragging = true;
});
// Mouseup : isDragging is false
$("#s1").bind('mouseup', function(event)
{
isDragging = false;
});
// Mousemove : handle window level, translation, zoom, slice changing
$("#s1").bind('mousemove', function(event)
{
if (isDragging)
{
switch (event.which)
{
case 1 : // left : window level
alert('left dragging');
break;
case 2 : // mousewheel : zoom
alert('mousewheel dragging');
break;
case 3 :
alert('right dragging');
break;
default :
}
}
});
【问题讨论】: