-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathjQuery.stickyFooter.js
76 lines (70 loc) · 2.14 KB
/
jQuery.stickyFooter.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
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
/*!
* jQuery Sticky Footer V1.0
* Copyright (c) 2017 claudchan
* MIT license
*/
;(function ($, window, document, undefined) {
var pluginName = 'stickyFooter',
defaults = {
wrapper: $('html'),
container: $('body'),
delay: 200
};
function Plugin(element, options) {
this.element = element;
this.options = $.extend( {}, defaults, options );
this._defaults = defaults;
this._name = pluginName;
this.init();
}
$.extend(Plugin.prototype, {
init: function () {
this.stickyFooter();
},
stickyFooter: function () {
var element = $(this.element),
wrapper = this.options.wrapper,
container = this.options.container,
delay = this.options.delay,
_update = function () {
wrapper.css({ 'position': 'relative', 'min-height': '100%' });
element.css({ 'position': 'absolute', 'bottom': '0', 'margin': '0', 'width': '100%' });
container.css('margin-bottom', element.outerHeight());
},
resize = false;
_update();
$(window).on('resize', function () {
resize = true;
});
setInterval(function () {
if(resize) {
resize = false;
_update();
}
}, delay);
}
});
$.fn[pluginName] = function ( options ) {
var args = arguments;
if (options === undefined || typeof options === 'object') {
return this.each(function () {
if (!$.data(this, 'plugin_' + pluginName)) {
$.data(this, 'plugin_' + pluginName, new Plugin( this, options ));
}
});
}
else if (typeof options === 'string' && options[0] !== '_' && options !== 'init') {
var returns;
this.each(function () {
var instance = $.data(this, 'plugin_' + pluginName);
if (instance instanceof Plugin && typeof instance[options] === 'function') {
returns = instance[options].apply( instance, Array.prototype.slice.call( args, 1 ) );
}
if (options === 'destroy') {
$.data(this, 'plugin_' + pluginName, null);
}
});
return returns !== undefined ? returns : this;
}
};
})(jQuery, window, document);