var localCount = 0; if(localCount === 0){ $('html').mouseleave(function(){ $.magnificPopup.open({ items: { src: '#openafter', }, type: 'inline' }); localCount++; }); } 

Conditions are not really the second time, but for some reason popup opens. I check via console.log. Values ​​for localCount always change

  • Well, so the check only happens once, and then the handler will just work it out - Grundy
  • How can I fix this? - Daniel qwaqwaqwa
  • move the check inside the handler for example - Grundy

1 answer 1

So it will be true:

 var localCount = 0; $('html').mouseleave(function(){ if(localCount === 0){ $.magnificPopup.open({ items: { src: '#openafter', }, type: 'inline' }); localCount++; } }); 

For after this line: $('html').mouseleave(function(){ , you specify the actions to be performed at the mouseleave event, respectively, and the condition that it has the effect again, must be inside the handler function of this event.

  • Better, of course, use one. $('html').one('mouseleave', function(){ $.magnificPopup.open({ items: { src: '#openafter', }, type: 'inline' }); }); - Petr Chalov 3:53 pm