-
Notifications
You must be signed in to change notification settings - Fork 2
/
ripstop.js
35 lines (33 loc) · 783 Bytes
/
ripstop.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
/*
* ripstop
* Cam Pedersen
* Feb 17, 2012
*/
/*
* usable with pure dom access
* ripstop(document.getElementById('el'));
*/
var ripstop = function (el) {
// apply ontouchstart to the first child
var children = el.getElementsByTagName('*');
children[0].ontouchstart = function () {
var x = el.scrollTop;
// check for bottom
var distanceFromBottom = children[0].offsetHeight - (x + el.offsetHeight);
if (distanceFromBottom == 0) el.scrollTop = children[0].offsetHeight - el.offsetHeight - 1;
// check for top
if (x > 0) return;
el.scrollTop = 1;
}
}
/*
* usable with jquery
* $('#el').ripstop();
*/
if (typeof jQuery != 'undefined') {
(function ($) {
$.fn.ripstop = function () {
ripstop(this.get(0));
};
})(jQuery);
}