-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathjquery-scrollFix.js
More file actions
55 lines (44 loc) · 1.21 KB
/
jquery-scrollFix.js
File metadata and controls
55 lines (44 loc) · 1.21 KB
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
//* jQuery - scrollFix 0.01.00 | Copyright (c) 2013 Nikita "IgelHaut" Nitichevski | MIT License *//
(function($) {
"use strict";
$.fn.scrollFix = function(options) {
return this.each(function() {
var config = $.extend({
"offsetX": 0,
"offsetY": 0
}, $.fn.scrollFix.defaults, options);
var element = $(this);
if(config.createContainer) {
element.wrapAll('<div class="jquery-scrollFix-container"></div>');
element = element.parent();
}
if(config.keepSize) {
element.wrapAll('<div class="jquery-scrollFix-sizeContainer"></div>');
element.parent().width(element.outerWidth()).height(element.outerHeight());
}
config.offsetX = element.offset().left;
config.offsetY = element.offset().top;
element.css({
"position": "fixed"
});
$(window).on('scroll', function() {
var x = 0;
if(!config.moveX)
x = -$(window).scrollLeft();
var y = 0;
if(!config.moveY)
y = -$(window).scrollTop();
element.css({
"left": config.offsetX+x,
"top": config.offsetY+y
});
});
});
};
$.fn.scrollFix.defaults = {
"moveX": false,
"moveY": true,
"createContainer": true,
"keepSize": true
};
} (jQuery));