forked from SethBurkart123/BetterSEQTA-theme-generator
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtest.html
142 lines (123 loc) · 3.88 KB
/
test.html
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
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
<html>
<head>
<style type="text/css">
.scrollview {
position:relative;
overflow:hidden;
width:300px;
height:400px;
background-color:black;
}
.scrollviewcontent {
position:absolute;
top:0px;
left:0px;
width:100%;
height:800px;
background-color:gray;
background-image:url(http://farm3.static.flickr.com/2242/2383475731_26167652d2_o_d.jpg);
}
</style>
<script type="text/javascript" language="javascript">
var scrollrange = 400.0;
var bounceheight = 200.0;
var animationtimestep = 1/20.0;
var mousedownpoint = null;
var translatedmousedownpoint = null;
var currentmousepoint = null;
var animationtimer = null;
var velocity = 0;
var position = 0;
var returntobaseconst = 1.5;
var decelerationconst = 100.0;
var bouncedecelerationconst = 1500.0;
function scrollviewdown() {
if ( animationtimer ) stopanimation();
mousedownpoint = event.screenY;
translatedmousedownpoint = mousedownpoint;
currentmousepoint = mousedownpoint;
animationtimer = setInterval("updatescrollview()", animationtimestep);
}
function scrollviewup() {
mousedownpoint = null;
currentmousepoint = null;
translatedmousedownpoint = null;
}
function scrollviewmove() {
if ( !mousedownpoint ) return;
currentmousepoint = event.screenY;
}
function updatescrollview() {
var oldvelocity = velocity;
// If mouse is still down, just scroll instantly to point
if ( mousedownpoint ) {
// First assume not beyond limits
var displacement = currentmousepoint - translatedmousedownpoint;
velocity = displacement / animationtimestep;
translatedmousedownpoint = currentmousepoint;
// If scrolled beyond top or bottom, dampen velocity to prevent going
// beyond bounce height
if ( (position > 0 && velocity > 0) || ( position < -1 * scrollrange && velocity < 0) ) {
var displace = ( position > 0 ? position : position + scrollrange );
velocity *= (1.0 - Math.abs(displace) / bounceheight);
}
}
else {
if ( position > 0 ) {
// If reach the top bound, bounce back
if ( velocity <= 0 ) {
// Return to 0 position
velocity = -1 * returntobaseconst * Math.abs(position);
}
else {
// Slow down in order to turn around
var change = bouncedecelerationconst * animationtimestep;
velocity -= change;
}
}
else if ( position < -1 * scrollrange ) {
// If reach bottom bound, bounce back
if ( velocity >= 0 ) {
// Return to bottom position
velocity = returntobaseconst * Math.abs(position + scrollrange);
}
else {
// Slow down
var change = bouncedecelerationconst * animationtimestep;
velocity += change;
}
}
else {
// Free scrolling. Decelerate gradually.
var changevelocity = decelerationconst * animationtimestep;
if ( changevelocity > Math.abs(velocity) ) {
velocity = 0;
stopanimation();
}
else {
velocity -= (velocity > 0 ? +1 : -1) * changevelocity;
}
}
}
// Update position
position += velocity * animationtimestep;
// Update view
scrollviewcontent = document.getElementById("thescrollviewcontent");
scrollviewcontent.style.top = Math.round(position) + 'px';
}
function stopanimation() {
clearInterval(animationtimer);
animationtimer = null;
}
</script>
</head>
<body>
<div id="thescrollview" class="scrollview">
<div id="thescrollviewcontent" class="scrollviewcontent"
onmousedown="scrollviewdown();"
onmouseup="scrollviewup();"
onmouseout="scrollviewup();"
onmousemove="scrollviewmove();">
</div>
</div>
</body>