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

前端 未结 9 1364
北荒
北荒 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条回答
  •  猫巷女王i
    2020-11-29 21:17

    I just made something like that (If I understand you correctly).

    I use he function position() include in jQuery 1.3.2.

    Just did a copy paste and a quick tweak... But should give you the idea.

    // Make images draggable.
    $(".item").draggable({
    
        // Find original position of dragged image.
        start: function(event, ui) {
    
            // Show start dragged position of image.
            var Startpos = $(this).position();
            $("div#start").text("START: \nLeft: "+ Startpos.left + "\nTop: " + Startpos.top);
        },
    
        // Find position where image is dropped.
        stop: function(event, ui) {
    
            // Show dropped position.
            var Stoppos = $(this).position();
            $("div#stop").text("STOP: \nLeft: "+ Stoppos.left + "\nTop: " + Stoppos.top);
        }
    });
    
    
    Waiting for dragging the image get started...
    Waiting image getting dropped...

提交回复
热议问题