如何在使用 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