-
Notifications
You must be signed in to change notification settings - Fork 63
Expand file tree
/
Copy pathscrollfix.js
More file actions
49 lines (39 loc) · 1.09 KB
/
Copy pathscrollfix.js
File metadata and controls
49 lines (39 loc) · 1.09 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
/**
* ScrollFix v0.1
* http://www.joelambert.co.uk
*
* Copyright 2011, Joe Lambert.
* Free to use under the MIT license.
* http://www.opensource.org/licenses/mit-license.php
*/
(function () {
var ScrollFix = function(elem) {
// Variables to track inputs
var startY, startTopScroll;
elem = elem || document.querySelector(elem);
// If there is no element, then do nothing
if(!elem) {
return;
}
// Handle the start of interactions
elem.addEventListener('touchstart', function(event){
startY = event.touches[0].pageY;
startTopScroll = elem.scrollTop;
if(startTopScroll <= 0) {
elem.scrollTop = 1;
}
if(startTopScroll + elem.offsetHeight >= elem.scrollHeight) {
elem.scrollTop = elem.scrollHeight - elem.offsetHeight - 1;
}
}, false);
};
// if we've got a window and we don't have a module
// create a global;
if ((typeof window != 'undefined') && (typeof module == 'undefined')) {
window.ScrollFix = ScrollFix;
}
// otherwise, export it.
else {
module.exports = ScrollFix;
}
})();