javascriptjqueryjquery-eventsmouseentermouseout

Mouseout & Mouseenter


When mouse pointer leaves the browser page a popup screen will be triggered. And when I enter the browser page again, the popup screen should disappear, but now I have to click on the close button in the popup to remove it.
How can I disappear the popup as soon as you enter the browser page again?

I have used this Javascript code:

// Exit intent
function addEvent(obj, evt, fn) {
  if (obj.addEventListener) {
    obj.addEventListener(evt, fn, false);
  } else if (obj.attachEvent) {
    obj.attachEvent("on" + evt, fn);
  }
}
// Exit intent trigger
addEvent(document, 'mouseout', function(evt) {
  if (evt.toElement == null && evt.relatedTarget == null) {
    $('.lightbox').slideDown();
  };
});
// Closing the Popup Box
$('a.close').click(function() {
  $('.lightbox').slideUp();
});

Solution

  • Trigger it by the mouseover event

    addEvent(document, 'mouseover', function(evt) {
      if (evt.toElement == null && evt.relatedTarget == null) {
        $('.lightbox').slideUp();
      };
    });