forked from Automattic/antiscroll
-
Notifications
You must be signed in to change notification settings - Fork 1
/
scrollbar.js
52 lines (40 loc) · 1.65 KB
/
scrollbar.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
/*global define: false, require: false, jQuery: false */
(function ($) {
"use strict";
$.fn.scrollbar = function (opts) {
opts = opts || {};
return $(this).each(function () {
if ($.data(this, 'antiscrolled')) { return; }
$.data(this, 'antiscrolled', 'true');
var wrappers = $('<div class="box-wrap antiscroll-wrap"><div class="box"><div class="antiscroll-inner"></div></div></div>'),
inners = $('<div class="box-inner"></div>'),
target = $(this),
cssfloat = target.css('float'),
width = target.outerWidth(),
height = target.outerHeight(),
position = target.css('position'),
left = target.css('left'),
top = target.css('top');
target
.css({width: 'auto', height: 'auto', left: 'auto', top: 'auto', position: 'static'})
.after(wrappers);
inners.append(target);
wrappers
.css({float: cssfloat, left: left, top: top})
.find('.box')
.css({width: width, height: height})
.end()
.find('.antiscroll-inner')
.css({width: width, height: height})
.append(inners)
.end()
.antiscroll(opts);
//For Safari 5.0.5
if (inners.width() !== width) {
wrappers
.find('.antiscroll-inner')
.css({width: 2 * width - inners.width(), height: height + width - inners.width()});
}
});
};
}(jQuery));