dragenter 요소를 추적해야 합니다. 그리고 끌어놓기 에 발동되었습니다. 개별 요소에서 dragenter 및 dragleave를 수신하면 해당 요소의 이벤트뿐만 아니라 자식의 이벤트도 캡처됩니다.
$.fn.draghover = function(options) {
return this.each(function() {
var collection = $(),
self = $(this);
self.on('dragenter', function(ev) {
if (collection.length === 0) {
self.trigger('draghoverstart');
}
collection = collection.add(ev.target);
});
self.on('dragleave drop', function(ev) {
collection = collection.not(ev.target);
if (collection.length === 0) {
self.trigger('draghoverend');
}
});
});
}; 이벤트 수신 -
$(window).draghover().on({
'draghoverstart': function() {
alert(‘dragged into the window');
},
'draghoverend': function() {
alert('dragged out of window');
}
});