leave screen popup with magnific popup pass data-effect

963 views Asked by At

I have looked at many examples for passing data from Javascript to Magnific pop-up, when the mouse leaves the screen the pop-up will fire 1 time and then you will have to refresh the page. However I cannot get the pop-up to animate or have and effect. I would like to use mfp-3d-unfold or mfp-zoom-out as an effect and #test-popup div id as the content Could someone help me how to fix the code.. I am really confused at this point. TKS

<html>
<head>
<title> Test leave Screen New 2</title>
<script type='text/javascript' src='js/jquery-1.10.2.min.js'></script>

<link rel='stylesheet prefetch' href='magni/magnific-popup.css'>
<link rel="stylesheet" href="magni/magnimain1.css" media="all">
<script src="magni/prefixfree.min.js"></script>

<script>
visitchecka = 0;
$(document).on('mouseleave', leaveFromTop);


function leaveFromTop(e){
    if( e.clientY < 0 ) // less than 60px is close enough to the top

         if (visitchecka < 1 ) {
         visitchecka++;
         visitchecka++;
        // window.location='#test-popup'.css;



$.magnificPopup.open({
items : {
mainclass: 'mfp-zoom-out',
src: '#test-popup',
},
type: 'inline',
});



         }
}
</script>

</head>
<body>


<div class="links">
  <h4>Text-based:</h4>
  <ul id="inline-popups">
    <li><a href="#test-popup" data-effect="mfp-3d-unfold">3d unfold</a></li>
    <li><a href="#test-popup" data-effect="mfp-zoom-out">Zoom-out</a></li>
  </ul>

  <a href="#test-popup" class="hinge">Popup with "hinge" close effect</a> (based on animate.css)



</div>



<!-- Popup itself -->
<div id="test-popup" class="white-popup mfp-with-anim mfp-hide">You may put any HTML here. This is dummy copy. It is not meant to be read. It has been placed here solely to demonstrate the look and feel of finished, typeset text. Only for show. He who searches for meaning here will be sorely disappointed.foofoo</div>




<script src='magni/jquery.min213.js'></script>
<script src='magni/jquery.magnific-popup.min.js'></script>
<script src="magni/index.js"></script>

</body>
</html>
1

There are 1 answers

0
Talha Habib On

You can do it by using .click() simply call your element to trigger click and popup will open on window leave... here I've made an example for you..

$('#clickme').magnificPopup({
  delegate: 'a',
  removalDelay: 500, 
  callbacks: {
    beforeOpen: function() {
       this.st.mainClass = this.st.el.attr('data-effect');
    }
  },
  midClick: true 
});

// this is what you need 
    $(".main").mouseleave(function(){ // your window or parent element you can use document if you want
             $('.popup').click(); // trigger click for popup
    });