This time I will share jQuery Plugin and tutorial about Lightweight Exit Modal Plugin With jQuery And Bootstrap – exit-modal, hope it will help you in programming stack.
exit-modal is an useful jQuery plugin for your landing page that displays a custom Bootstrap modal window when the users try to exit the current page. The plugin detects the mousemove event and triggers a modal popup when you put the cursor outside the viewport.
How to use it:
1. Load the jQuery exit-modal plugin together with jQuery library and Bootstrap framework in your webpage.
1 |
< link rel = "stylesheet" href = "bootstrap.min.css" > |
2 |
< script src = "jquery.min.js" ></ script > |
3 |
< script src = "bootstrap.min.js" ></ script > |
4 |
< script src = "jquery.exit-modal.js" ></ script > |
2. Create custom content for your exit modal.
01 |
< div class = "modal exit-modal fade" > |
02 |
< div class = "modal-dialog" > |
03 |
< div class = "modal-content" > |
04 |
< div class = "modal-header" > |
05 |
< button type = "button" class = "close" data-dismiss = "modal" aria-label = "Close" >< span aria-hidden = "true" >×</ span ></ button > |
06 |
< h4 class = "modal-title" >Exit modal</ h4 > |
08 |
< div class = "modal-body" > |
09 |
< p >Exit modal body</ p > |
11 |
< div class = "modal-footer" > |
12 |
< button type = "button" class = "btn btn-primary close-exit-modal" >Close exit modal</ button > |
3. Call the function on the modal window and done.
4. Advanced usage.
03 |
var exitModalParams = { |
05 |
callbackOnModalShow: function () { |
06 |
var counter = $( '.exit-modal' ).data( 'exitModal' ).showCounter; |
07 |
$( '.exit-modal .modal-body p' ).text( "Exit modal shown " +counter+ " times" ); |
09 |
callbackOnModalShown: function () { |
10 |
timer = setTimeout( function (){ |
11 |
window.location.href = "http://" ; |
14 |
callbackOnModalHide: function () { |
19 |
$( '.exit-modal' ).exitModal(exitModalParams); |
21 |
$( '.destroy-exit-modal' ).on( "click" , function (e){ |
23 |
$( '.exit-modal' ).exitModal( 'destroy' ); |
26 |
$( '.init-exit-modal' ).on( 'click' , function (e){ |
28 |
$( '.exit-modal' ).exitModal(exitModalParams); |
31 |
$( '.close-exit-modal' ).on( 'click' , function (e){ |
33 |
$( '.exit-modal' ).exitModal( 'hideModal' ); |
5. Default plugin options.
01 |
viewportSelector: document, |
02 |
showButtonClose: true , |
03 |
showButtonCloseOnlyForMobile: true , |
04 |
pageYValueForEventFired: 10, |
08 |
modalShowEvent: 'show.bs.modal' , |
09 |
modalShownEvent: 'shown.bs.modal' , |
10 |
modalHideEvent: 'hide.bs.modal' , |
11 |
modalHiddenEvent: 'hidden.bs.modal' , |
12 |
callbackOnModalShow: function () { }, |
13 |
callbackOnModalShown: function () { }, |
14 |
callbackOnModalHide: function () { }, |
15 |
callbackOnModalHidden: function () { } |
This awesome jQuery plugin is developed by kwarc87. For more Advanced Usages, please check the demo page or visit the official website.