Firefox doesn\'t properly trigger the dragleave event when dragging outside of the window:
https://bugzilla.mozilla.org/show_bug.cgi?id=665704
https://bugzil
Inspired by @PhilipWalton 's code, I simplified the jQuery plugin code.
$.fn.draghover = function(fnIn, fnOut) {
return this.each(function() {
var n = 0;
$(this).on('dragenter', function(e) {
(++n, n==1) && fnIn && fnIn.call(this, e);
}).on('dragleave drop', function(e) {
(--n, n==0) && fnOut && fnOut.call(this, e);
});
});
};
Now you can use the jquery plugin like jquery hover method:
// Testing code 1
$(window).draghover(function() {
console.log('into window');
}, function() {
console.log('out of window');
});
// Testing code 2
$('#d1').draghover(function() {
console.log('into #d1');
}, function() {
console.log('out of #d1');
});