Retrieving the “snapped to” element using jQuery UI draggable with snap enabled

老子叫甜甜 提交于 2020-01-23 12:08:08

问题


I'm using jQuery UI's draggable, with 'snap' enabled and set to select a class of elements. This means that the draggable snaps to the edges of (for example) a class called .general.

When the draggable is snapping to an element of class .general, is it possible to find or select that exact 'snapped to' element?


回答1:


You can try doing something like this, which will harvest the elements it is snapping to:

$( ".selector" ).draggable({
   stop: function(event, ui) {
            var snappedTo = $.map($(this).data('draggable').snapElements, function (element) {
                if (element.snapping) { return element; }
            });
   }
});


来源:https://stackoverflow.com/questions/4220557/retrieving-the-snapped-to-element-using-jquery-ui-draggable-with-snap-enabled

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