Firefox firing dragleave when dragging over text

后端 未结 4 1029
南方客
南方客 2020-12-19 06:07

I\'m attempting to track a dragenter/leave for the entire screen, which is so far working fine in Chrome/Safari, courtesy of the draghover plugin from https://stackoverflow.

4条回答
  •  旧时难觅i
    2020-12-19 06:42

    I came up with kind of a solution, yet to test on other browsers other than Chrome and FF but working so far. This is how the setTimeout looks now:

    setTimeout( function() {
        var isChild = false;
    
        // in order to get permission errors, use the try-catch
        // to check if the relatedTarget is a child of the body
        try {
            isChild = $('body').find(e.relatedTarget).length ? true : isChild;
        }
        catch(err){} // do nothing
    
        collection = collection.not(e.target);
        if (collection.size() === 0 && !isChild) {
            self.trigger('draghoverend');
        }
    }, 1);
    

    The entire code here - http://jsfiddle.net/tusRy/13/.

    The idea is to check if the related tag is a child of the body, in which case we are still in the Browsers and the draghoverend event should be not triggered. As this can throw errors when moving out of the windows, I used a try method to avoid it.

    Well, perhaps somebody with more skills on JS could improve this :)

提交回复
热议问题