jQuery UI : Before start draggable

前端 未结 4 1260

How to implement a before start event to have a change to change the position and place in the DOM of the draggable element before jQueryUI start to drag?

4条回答
  •  -上瘾入骨i
    2020-12-17 05:52

    I didn't dare to access jQuery UI private variables, so I implemented it like this:

    // The mouse interaction sequence for dragging starts with a mousedown action.
    element.on('mousedown', function() {
    
        // Mouseup cancels dragging. This is a boring click.
        element.one('mouseup', function() {
            element.off('mousemove.mynamespace');
        });
    
        // Moving the mouse while holding mousedown is dragging.
        // This is also what sets off jQuery UI draggable, 
        // but we registered our event listeners first.
        element.one('mousemove.mynamespace', function() {
    
             // !! Your beforeStart code here.
    
        });
    });
    
    // Initialize jQuery UI draggable AFTER our own event listeners.
    element.draggable();
    

提交回复
热议问题