Javascript mousedown和mouseup事件冲突

时间:2016-03-07 21:01:03

标签: javascript javascript-events event-handling mousedown

我正在创建一个简单的绘图网站。我想要实现的是我的菜单栏应该变得不可点击,而我的鼠标是关闭的(绘图时)。这工作正常,但在鼠标上,没有任何反应。我一直在谷歌搜索很长一段时间,但没有找到任何解决方案。有任何想法吗?谢谢! :)

var mousedDownFired = false;
  $("body").mousedown(function(event){
      mousedDownFired =true;
       document.body.style.pointerEvents = 'none';


  });

  $("body").mouseup(function(event){


     if(mousedDownFired)
      {
         mousedDownFired = false;
         return;
      }
      document.body.style.pointerEvents = 'auto';
 });

1 个答案:

答案 0 :(得分:0)

设置document.body.style.pointerEvents = 'none';时,会阻止mouseUp事件触发。

如果你想让你的菜单栏无法点击,只需将它的style.pointerEvents设置为'none',而不是整个文档正文。

相关问题