• <tfoot id='9TnUf'></tfoot>
        • <bdo id='9TnUf'></bdo><ul id='9TnUf'></ul>

        <small id='9TnUf'></small><noframes id='9TnUf'>

        <legend id='9TnUf'><style id='9TnUf'><dir id='9TnUf'><q id='9TnUf'></q></dir></style></legend>

      1. <i id='9TnUf'><tr id='9TnUf'><dt id='9TnUf'><q id='9TnUf'><span id='9TnUf'><b id='9TnUf'><form id='9TnUf'><ins id='9TnUf'></ins><ul id='9TnUf'></ul><sub id='9TnUf'></sub></form><legend id='9TnUf'></legend><bdo id='9TnUf'><pre id='9TnUf'><center id='9TnUf'></center></pre></bdo></b><th id='9TnUf'></th></span></q></dt></tr></i><div id='9TnUf'><tfoot id='9TnUf'></tfoot><dl id='9TnUf'><fieldset id='9TnUf'></fieldset></dl></div>

        jQuery在元素内检测mousedown,然后在元素外检测m

        时间:2023-09-04
        <legend id='Ie3zu'><style id='Ie3zu'><dir id='Ie3zu'><q id='Ie3zu'></q></dir></style></legend>
        <i id='Ie3zu'><tr id='Ie3zu'><dt id='Ie3zu'><q id='Ie3zu'><span id='Ie3zu'><b id='Ie3zu'><form id='Ie3zu'><ins id='Ie3zu'></ins><ul id='Ie3zu'></ul><sub id='Ie3zu'></sub></form><legend id='Ie3zu'></legend><bdo id='Ie3zu'><pre id='Ie3zu'><center id='Ie3zu'></center></pre></bdo></b><th id='Ie3zu'></th></span></q></dt></tr></i><div id='Ie3zu'><tfoot id='Ie3zu'></tfoot><dl id='Ie3zu'><fieldset id='Ie3zu'></fieldset></dl></div>
          <tbody id='Ie3zu'></tbody>

            <tfoot id='Ie3zu'></tfoot>
          1. <small id='Ie3zu'></small><noframes id='Ie3zu'>

              <bdo id='Ie3zu'></bdo><ul id='Ie3zu'></ul>

                1. 本文介绍了jQuery在元素内检测mousedown,然后在元素外检测mouseup的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

                  问题描述

                  我有一些类似于绘图画布的东西,我在 mouseup 上捕获它的状态以用于撤消目的.画布不是全屏的,因此您可以使用画笔绘制并在画布外释放.像这样的:

                  I have something similar to a drawing canvas, and I capture it's state on mouseup for undo purposes. The canvas isn't full screen, so you can draw with a brush and release outside the canvas. Something like this:

                  $("#element").mousedown(function(){
                    $(document).mouseup(function(){
                      //do something
                    }); 
                  });
                  

                  但这当然行不通.普通的 $(document).mouseup 也不起作用,因为我还有许多其他 UI 元素,并且每次单击 UI 元素时它都会保存状态.

                  But this doesn't work of course. A plain $(document).mouseup doesn't work either, because I have many other UI elements and it saves the state each time you click on a UI element.

                  有什么想法吗?

                  推荐答案

                  var isDown = false;
                  
                  $("#element").mousedown(function(){
                      isDown = true;
                  });
                  
                  $(document).mouseup(function(){
                      if(isDown){
                          //do something
                          isDown = false;
                      }
                  }); 
                  

                  为了简单起见,我将 isDown 放在全局命名空间中.在生产中,您可能希望隔离该变量的范围.

                  For the sake of simplicity I put isDown in the global namespace. In production you would probably want to isolate the scope of that variable.

                  这篇关于jQuery在元素内检测mousedown,然后在元素外检测mouseup的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持html5模板网!

                  上一篇:Vuejs - 冒泡自定义事件 下一篇:HTML5/JS 存储事件处理程序

                  相关文章

                  最新文章

                  <i id='g1UgF'><tr id='g1UgF'><dt id='g1UgF'><q id='g1UgF'><span id='g1UgF'><b id='g1UgF'><form id='g1UgF'><ins id='g1UgF'></ins><ul id='g1UgF'></ul><sub id='g1UgF'></sub></form><legend id='g1UgF'></legend><bdo id='g1UgF'><pre id='g1UgF'><center id='g1UgF'></center></pre></bdo></b><th id='g1UgF'></th></span></q></dt></tr></i><div id='g1UgF'><tfoot id='g1UgF'></tfoot><dl id='g1UgF'><fieldset id='g1UgF'></fieldset></dl></div>
                2. <legend id='g1UgF'><style id='g1UgF'><dir id='g1UgF'><q id='g1UgF'></q></dir></style></legend><tfoot id='g1UgF'></tfoot>

                      <small id='g1UgF'></small><noframes id='g1UgF'>

                      • <bdo id='g1UgF'></bdo><ul id='g1UgF'></ul>