-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.js
82 lines (67 loc) · 2.26 KB
/
main.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
77
78
79
80
81
82
"use strict";
var edgeSize = 200;
var timer = null;
window.addEventListener("mousemove", handleMousemove, false);
function handleMousemove(event) {
var viewportX = event.clientX;
var viewportWidth = document.documentElement.clientWidth;
var viewportHeight = document.documentElement.clientHeight;
var edgeLeft = edgeSize;
var edgeRight = (viewportWidth - edgeSize);
var isInLeftEdge = (viewportX < edgeLeft);
var isInRightEdge = (viewportX > edgeRight);
if (!(isInLeftEdge || isInRightEdge)) {
clearTimeout(timer);
return;
}
var documentWidth = Math.max(
document.body.scrollWidth,
document.body.offsetWidth,
document.body.clientWidth,
document.documentElement.scrollWidth,
document.documentElement.offsetWidth,
document.documentElement.clientWidth
);
var documentHeight = Math.max(
document.body.scrollHeight,
document.body.offsetHeight,
document.body.clientHeight,
document.documentElement.scrollHeight,
document.documentElement.offsetHeight,
document.documentElement.clientHeight
);
var maxScrollX = (documentWidth - viewportWidth);
var maxScrollY = ( documentHeight - viewportHeight );
(function checkForWindowScroll() {
clearTimeout(timer);
if (adjustWindowScroll()) {
timer = setTimeout(checkForWindowScroll, 30 );
}
})();
function adjustWindowScroll() {
var currentScrollX = window.pageXOffset;
var currentScrollY = window.pageYOffset;
var canScrollLeft = (currentScrollX > 0);
var canScrollRight = (currentScrollX < maxScrollX);
var nextScrollX = currentScrollX;
var nextScrollY = currentScrollY;
var maxStep = 50;
if (isInLeftEdge && canScrollLeft) {
var intensity = ((edgeLeft - viewportX) / edgeSize);
nextScrollX = (nextScrollX - ( maxStep * intensity));
}
else if (isInRightEdge && canScrollRight) {
var intensity = ((viewportX - edgeRight) / edgeSize);
nextScrollX = (nextScrollX + (maxStep * intensity));
}
nextScrollX = Math.max(0, Math.min( maxScrollX, nextScrollX));
nextScrollY = Math.max( 0, Math.min( maxScrollY, nextScrollY ) );
if (nextScrollX !== currentScrollX) {
window.scrollTo(nextScrollX, nextScrollY);
return( true );
}
else {
return( false );
}
}
}