Mouseout once

1

I would like to know how I can make this script work once, because I can not do it:

// intenção de sair
function addEvent(obj, evt, fn) {
    if (obj.addEventListener) {
        obj.addEventListener(evt, fn, false);
    }
    else if (obj.attachEvent) {
        obj.attachEvent("on" + evt, fn);
    }
}

// gatilho 
addEvent(document, 'mouseout', function(evt) {

    if (evt.toElement == null && evt.relatedTarget == null ) {
        $('#lightbox_overlay').slideDown();
    };

});

// fechando o popup           
$('#lightbox_overlay, #close').on('click', function(event) { 
    $('.lightbox').slideUp();                            
});
    
asked by anonymous 28.11.2018 / 21:34

1 answer

0

Using the {once: true} option indicates that the event will fire a maximum of 1 time before it is automatically removed ( documentation ):

obj.addEventListener(evt, fn, {once : true});

Unfortunately IE11 does not support, but is supported by 93% of browsers in Brazil and 86% global ( see Can I Use ).

    
29.11.2018 / 16:38