How do I get the coordinate position after using jQuery drag and drop?

前端 未结 9 1356
北荒
北荒 2020-11-29 20:36

How do I get the coordinate position after using jQuery drag and drop? I want to save the coordinate to a database, so that next time I visit, the item will be in that posi

9条回答
  •  孤独总比滥情好
    2020-11-29 21:13

    Cudos accepted answer is great. However, the Draggable module also has a "drag" event that tells you the position while your dragging. So, in addition to the 'start' and 'stop' you could add the following event within your Draggable object:

        // Drag current position of dragged image.
        drag: function(event, ui) {
    
            // Show the current dragged position of image
            var currentPos = $(this).position();
            $("div#xpos").text("CURRENT: \nLeft: " + currentPos.left + "\nTop: " + currentPos.top);
    
        }
    

提交回复
热议问题