问题
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