jQuery Plugin To Display A Popup After Visitor Is Idle - Sleepy Head Modal
File Size: | 10.3 KB |
---|---|
Views Total: | 3865 |
Last Update: | |
Publish Date: | |
Official Website: | Go to website |
License: | MIT |

Sleepy Head Modal is a jQuery plugin which listens for mouse move & key press events and displays a custom modal window when the visitor is 'AFK' for particular period in a webpage. Suitable for session timeout dialog, social share popup or email subscription form.
How to use it:
1. Include jQuery library and the jQuery sleepy head modal plugin at the bottom of the html page.
<script src="//code.jquery.com/jquery-1.11.3.min.js"></script> <script src="js/sleepy-head.js"></script>
2. Create the content for your 'Idle' modal.
<div class="sleepy-overlay"> <div class="sleepy-modal"> <div class="sleepy-header"> <span>Snoozing...</span> <div class="sleepy-close"> </div> </div> <div class="sleepy-content"> Modal Content Goes Here </div> <div class="sleepy-wake-up">Wake Up!</div> </div> </div>
3. The modal will appear after you visitor is idle for 10 seconds (10000 ms) in the webpage.You can customize the 'Idle' time in the sleepy-head.js
.
var idleInterval = setInterval(timerIncrement, 10000);
4. Style the 'Idle' modal popup whatever you like.
.sleepy-overlay { position: absolute; top: 0; left: 0; width: 100%; height: 100%; z-index: 10; background-color: rgba(0, 0, 0, 0.5); display: none; } .sleepy-modal { position: fixed; top: 50%; left: 50%; transform: translate(-50%, -50%); background: #fff; height: 250px; width: 400px; z-index: 11; -webkit-box-shadow: 1px 1px 5px 1px rgba(0, 0, 0, 0.25); box-shadow: 1px 1px 5px 1px rgba(0, 0, 0, 0.25); padding: 5px 10px; } .sleepy-header { font-family: Verdana, Verdana, Geneva, sans-serif; font-size: 16px; } .sleepy-header span { margin-top: 3px; } .sleepy-close { float: right; width: 16px; height: 16px; background-image: url("../img/sleepy-head-close-x.svg"); margin-top: 5px; cursor: pointer; } .sleepy-close:after { clear: both; } .sleepy-content, .sleepy-modal, .sleepy-wake-up { -webkit-border-radius: 5px 5px 5px 5px; border-radius: 5px 5px 5px 5px; } .sleepy-content { padding: 15px 10px; background: #eee; height: 142px; margin: 10px auto; } .sleepy-message { float: left; width: 65%; } .sleepy-message p { font-size: 14px; font-family: Verdana, Verdana, Geneva, sans-serif; } .sleepy-owl { float: left; width: 35%; } .sleepy-owl div { width: 110px; height: 122px; background-image: url("../img/sleepy-head-owl-default.svg"); } .sleepy-wake-up { font-family: Verdana, Verdana, Geneva, sans-serif; background: #b23445; color: #541819; text-shadow: 0 1px 0 #be5244; float: right; padding: 5px 10px; box-shadow: 0 1px 0 0 rgba(255, 255, 255, 0.3) inset; cursor: pointer; -webkit-transition: all 0.30s ease; -moz-transition: all 0.30s ease; -ms-transition: all 0.30s ease; -o-transition: all 0.30s ease; transition: all 0.30s ease; } .sleepy-wake-up:hover { color: #fff; } @media only screen and (max-width: 40em) { .sleepy-message p { display: none; } .sleepy-modal { width: 320px; height: 200px; } .sleepy-modal { -webkit-border-radius: 0px; border-radius: 0px } .sleepy-wake-up { margin-top: -60px; } .sleepy-message .sleepy-mobile-only { display: block; text-align: right; } } @media only screen and (min-width: 40.063em) { .sleepy-message .sleepy-mobile-only { display: none; } }
This awesome jQuery plugin is developed by SimonHayter. For more Advanced Usages, please check the demo page or visit the official website.