简体   繁体   English

如何捕获此事件,当我左键单击然后在div上移动一些位置(而不是拖动div)

[英]how to catch this event that when i left click and then move some where (not drag some div ) on a div

this is my code: 这是我的代码:

$('#handle').mousedown(function(e){
if( (!$.browser.msie && e.button == 0) || ($.browser.msie && e.button == 1) ) {
       alert("Left Button");
    }
})

this event is like to drag , but not drag , 此事件就像是拖动,但不是拖动,

the left button Has been pressed, no released until mouseup, 左按钮已被按下,直到将其上移后才松开,

so how to catch it using jquery , 那么如何使用jquery捕获它,

this is my demo : http://jsfiddle.net/ATZNW/1/ 这是我的演示: http : //jsfiddle.net/ATZNW/1/

thanks 谢谢

jQuery doesn't do this out of the box but you can fire your own events. jQuery并没有开箱即用,但是您可以触发自己的事件。 Instead of alerting "left button", set some global variable dragging to true. 而不是警告“左键”,而是将一些全局变量dragging为true。 Then: 然后:

$("#handle").mousemove(function (e) {
   if (dragging) {
      $(this).trigger("dragmove");
      // Or just write the code you need here
   }
});

Then you can handle that event elsewhere if you wish: 然后,您可以根据需要在其他地方处理该事件:

$("#handle").bind("dragmove", function (e) {

});

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 jQuery-如何将一些可选的div向左移动,单击按钮 - Jquery-how to move some selectable div into left ,on click a button 通过单击和拖动移动 div - Move div with click and drag 如果我在某些div之外单击,可以得到一个事件吗? - Can I get an event if i click outside some div? 单击某些文件时如何使用jstree在正确的div中显示内容 - how to use jstree to show content in right div when i click some file 如何在某些按钮单击时切换jsp中的div - How to toggle div in jsp on some button click 如何在每次点击时将div移至左侧-只是javascript no jquery - how to move div to left on every click - just javascript no jquery 如何在没有点击标记事件的情况下在谷歌地图中获取一些信息,并在除了infoWindow之外的div中显示 - How to get some information in google maps without click event on marker and show this in a div, other than infoWindow 如何在点击时创建div元素? 而div适用于我点击的位置 - How to create a div element on click? And the div to appper where I click 当我使用简单的 javascript 单击按钮时,如何在 div 标签中的另一个文件上添加一些 Html 代码 - How to add some Html code which on another file in a div tag when I click a button using simple javascript jQuery - 如何将一些带有文本的标记元素移动到最近的div中 - jQuery - How to move some tag element with text inside to closest div
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM