jquery ui drag element without keeping mouse button down (follow the cursor)

青春壹個敷衍的年華 提交于 2019-12-13 00:23:24

问题


I am trying to drag an element without keeping the mouse button down.

The behavior I would like is :

  1. I click on a draggable item
  2. Drag my item without keeping mouse left click down : just follow the mouse as a cursor
  3. I click on a droppable container to confirm and append my item

I am able to simulate this behavior if I add an alert box durring the start event.

    start : function(){
        alert('test')
    },

Here is the fiddle : http://jsfiddle.net/QvRjL/103/

How is it possible to code this behavior without the alert box?


回答1:


Here is a good solution about this problem : Trigger Click-and-Hold Event

http://jsfiddle.net/VXbpu/1/

http://jsfiddle.net/vPruR/70/

var click = false;

$(document).bind('mousemove', function (e) {
    if (click == true) {
        $('#your_div_id').css({
            left: e.pageX,
            top: e.pageY
        });
    }
});

$('#your_div_id').click(function() {
    click = !click;
    return false;
});

$('html').click(function() {
    click = false;
});


来源:https://stackoverflow.com/questions/13518371/jquery-ui-drag-element-without-keeping-mouse-button-down-follow-the-cursor

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!