-
Notifications
You must be signed in to change notification settings - Fork 0
/
modalpop.js
62 lines (49 loc) · 1.48 KB
/
modalpop.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
//ModalPop
//Author: Owain Lewis
//Author URL: www.Owainlewis.com
//Simple Modal Dialog for jQuery
//The idea here was to keep this plugin as lightweight and easy to customize as possible
//You are free to use this plugin for whatever you want.
//If you enjoy this plugin, I'd love to hear from you
(function(){
jQuery.fn.modalpop = function(options){
var defaults = {
speed:500,
center:false
};
var options = $.extend(defaults, options);
var width = $(window).width();
//Get the full page height including the scroll area
var height = $(document).height();
jQuery('body').prepend("<div id='mask'></div>");
jQuery('#mask').css('height',height);
jQuery('#mask').css('width',width);
return this.each(function(){
jQuery(this).click(function(){
$this = jQuery(this);
var id = $this.attr('href');
//Get the window height and width
var winH = height;
var winW = width;
//Set the popup window to center if required
if (defaults.center == true){
$(id).css('top', winH/2-$(id).height()/2);
}else{
$(id).css('top', 200);
}
$(id).css('left', winW/2-$(id).width()/2);
jQuery('#mask').fadeIn(defaults.speed);
jQuery(id).fadeIn(defaults.speed);
return false;
});
jQuery('#mask').click(function(){
jQuery(this).fadeOut(defaults.speed);
jQuery('.window').fadeOut(defaults.speed);
});
jQuery('.close').click(function(){
jQuery(this).fadeOut(defaults.speed);
jQuery('.window').fadeOut(defaults.speed);
});
});
};
})(jQuery);