如何在使用 HTML 将拖拽事件拖拽出窗口时检测 Firefox 中的 dragleave 事件?
您需要跟踪触发了哪些元素dragenter 和dragleave 。在单个元素上监听 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');
}
});
广告
Data Structure
Networking
RDBMS
Operating System
Java
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP