Flash对象上的Mouseup事件未触发

时间:2011-04-08 00:54:14

标签: javascript jquery flash javascript-events

我在jQuery(文档)范围内从How to get mouseup to fire once mousemove complete开始使用此脚本。

后来我在体内添加了一个flash对象。当我点击flash对象时,mousedown事件被触发,mousemove事件被触发,但不是mouseup事件,我要取消绑定mousemove。

但是当我点击非Flash区域时,mousedown工作,mousemove工作,mouseup也可以工作。它的效果就像我想要的一样,但不适用于Firefox。

以下是代码,我在handleMouseDown

中致电$(document).ready
handleMouseDown: function () {
    jQuery(document).mouseup(function() {
        Log("unbind.");
        jQuery(document).unbind('mousemove');
    }); 

    jQuery(document).mousedown(function(e) { 
      Log('click');
      // You can record the starting position with
      var start_x = e.pageX;
      var start_y = e.pageY;

      jQuery(document).mousemove(function(e) {
          // And you can get the distance moved by
          var offset_x = e.pageX - start_x;
          var offset_y = e.pageY - start_y;

          Log('moves') ;
          return false;
      }); 

      // Using return false prevents browser's default,
      // often unwanted mousemove actions (drag & drop)
      return false;
  }); 
}
//firebug method log calls
function Log(str) {
    if (typeof(console.log) == 'function') console.log(str);
}

5 个答案:

答案 0 :(得分:0)

这有点难以处理。

首先关闭任何flash对象将捕获所有输入。这意味着任何鼠标或键盘事件都在flash对象中!虽然键盘输入仅在元素具有焦点时捕获,但mouseUp仍将出现在flash对象中。

其次,我能想到的唯一解决方案是,当mouveUp被触发时,用前景不可见的div覆盖所有flash对象。可能会工作......可能不会,但理论上它应该。

答案 1 :(得分:0)

当鼠标按钮通过Flash对象释放时,您可以将鼠标放在一个单独的函数中,该函数可以从JavaScript处理程序调用,也可以从Flash调用ExternalInterface调用。当然,这只有在您可以编辑Flash源时才有效。

答案 2 :(得分:0)

我可以像这样解决这个问题:

$('object').live('mousedown', function() {
    alert('I was clicked');
});

只有.bind()没有完成这项工作,可能是因为该对象是通过swfobject插入的......

答案 3 :(得分:0)

这是一个古老的问题,但似乎没有一个合适的答案,所以我只是说我如何解决它,因为它今天仍然是一个问题。虽然mouseup事件似乎没有触发flash对象,但通用' click'如果您要跟踪自己的情况,事件就会发生。并且' down'您应该能够使用它来获得您想要的状态。超级基本的例子:

$(document).on("mousedown", function () {
    mouseButtonStatus = "down";
});

$(document).on("mouseup", function () {
    mouseButtonStatus = "up";
});

// This little bodge gets around the issue with FireFox and the mouseup event
$(document).on("click", function () {
    if (mouseButtonStatus === "down"){
        mouseButtonStatus = "up";
    }
});

不用说适当地调整你的变量等等......

答案 4 :(得分:0)

另一种解决方案是使用MouseEvent.buttons属性,具体为 Firefox ,因为它是 Firefox 怪癖。例如, Safari 中不提供此属性。以下是检测左按钮是否被按下的代码,注意touchmove检查以避免触摸设备上的触发:

if ( e.buttons != 'undefined' && e.type != 'touchmove'  && !(e.buttons & 1 ) ) 
bMouseDown = false;
相关问题