Last active
December 13, 2016 20:12
-
-
Save monkishtypist/00f7e9620615aad5c1fb4052359bfb48 to your computer and use it in GitHub Desktop.
Bootstrap Exit Pop
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* Simple Bootstrap jQuery Exit Pop | |
* Trigger an existing Bootstrap modal on mouseleave() | |
*/ | |
/* This first version uses a variable to determine when to trigger pop. */ | |
(function(){ | |
var pop = false; /* it has not pop'd */ | |
jQuery(document).mouseleave(function(){ | |
if(!pop || typeof pop === 'undefined'){ | |
jQuery('#myModal').modal('show'); /* show the modal */ | |
pop = true; /* it has pop'd */ | |
}; | |
}); | |
})(jQuery); | |
/* This second version unsets `mouseleave()` once it has been triggered. */ | |
(function(){ | |
jQuery(document).on('mouseleave', function(){ | |
jQuery('#myModal').modal('show'); | |
jQuery(document).off('mouseleave'); /* unset the trigger */ | |
}); | |
})(jQuery); | |
/* This third version checks that the mouse has left at the top. This prevent scrollbar triggering exit pop. */ | |
(function(){ | |
jQuery(document).on('mouseleave', function(e){ | |
if(e.clientY < 0){ /* only trigger if leave top */ | |
jQuery('#myModal').modal('show'); | |
jQuery(document).off('mouseleave'); | |
} | |
}); | |
})(jQuery); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Example:
Dev Tools