Simple jQuery Plugin For Opening A Popup Window On Page load
File Size: | 5.19 KB |
---|---|
Views Total: | 298582 |
Last Update: | |
Publish Date: | |
Official Website: | Go to website |
License: | MIT |
A tiny and easy jQuery plugin that automatically opens a dialog pop-up with cool transition effect when the web page loads.
How to use it:
1. Create the content for your popup.
<div id="boxes"> <div id="dialog" class="window"> Your Content Goes Here <div id="popupfoot"> <a href="#" class="close agree">I agree</a> | <a class="agree"style="color:red;" href="#">I do not agree</a> </div> </div> <div id="mask"></div> </div>
2. The sample CSS to style the popup window.
#mask { position: absolute; left: 0; top: 0; z-index: 9000; background-color: #000; display: none; } #boxes .window { position: absolute; left: 0; top: 0; width: 440px; height: 200px; display: none; z-index: 9999; padding: 20px; border-radius: 15px; text-align: center; } #boxes #dialog { width: 750px; height: 300px; padding: 10px; background-color: #ffffff; font-family: 'Segoe UI Light', sans-serif; font-size: 15pt; } #popupfoot { font-size: 16pt; position: absolute; bottom: 0px; width: 250px; left: 250px; }
3. Include the necessary jQuery library at the bottom of the web page.
<script src="//ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.js"></script>
4. The Javascript to open the popup window on document ready.
$(document).ready(function() { var id = '#dialog'; //Get the screen height and width var maskHeight = $(document).height(); var maskWidth = $(window).width(); //Set heigth and width to mask to fill up the whole screen $('#mask').css({'width':maskWidth,'height':maskHeight}); //transition effect $('#mask').fadeIn(500); $('#mask').fadeTo("slow",0.9); //Get the window height and width var winH = $(window).height(); var winW = $(window).width(); //Set the popup window to center $(id).css('top', winH/2-$(id).height()/2); $(id).css('left', winW/2-$(id).width()/2); //transition effect $(id).fadeIn(2000); //if close button is clicked $('.window .close').click(function (e) { //Cancel the link behavior e.preventDefault(); $('#mask').hide(); $('.window').hide(); }); //if mask is clicked $('#mask').click(function () { $(this).hide(); $('.window').hide(); }); });
This awesome jQuery plugin is developed by fleroviums. For more Advanced Usages, please check the demo page or visit the official website.