summaryrefslogtreecommitdiff
path: root/js
diff options
context:
space:
mode:
authorDirk Engling <erdgeist@erdgeist.org>2016-08-08 02:16:04 +0200
committerDirk Engling <erdgeist@erdgeist.org>2016-08-08 02:16:04 +0200
commit9b703ebb8484808d76714a5409b3d961479f90cb (patch)
tree83a389c70292680603e5d91766ac41e00654d52e /js
parentc89a122300ec832b4b5d439322b0c0853d9f864e (diff)
change scroller routine to make it work on mobile browsers
Diffstat (limited to 'js')
-rw-r--r--js/abmahn.js31
1 files changed, 17 insertions, 14 deletions
diff --git a/js/abmahn.js b/js/abmahn.js
index af8f000..7237901 100644
--- a/js/abmahn.js
+++ b/js/abmahn.js
@@ -12,23 +12,26 @@ function setText(input, text) {
12 document.getElementById(input).value = text; 12 document.getElementById(input).value = text;
13} 13}
14 14
15function scrollTo(element, to, duration) { 15function scrollTo(to, duration) {
16 if (duration <= 0) return; 16 if (document.body.scrollTop == to) return;
17 var difference = to - element.scrollTop; 17 var diff = to - document.body.scrollTop;
18 var perTick = difference / duration * 2; 18 var scrollStep = Math.PI / (duration / 10);
19 19 var count = 0, currPos;
20 setTimeout(function() { 20 start = document.body.scrollTop;
21 element.scrollTop = element.scrollTop + perTick; 21 scrollInterval = setInterval(function(){
22 scrollTo(element, to, duration - 2); 22 if (document.body.scrollTop != to) {
23 }, 10); 23 count = count + 1;
24 currPos = start + diff * (0.5 - 0.5 * Math.cos(count * scrollStep));
25 document.body.scrollTop = currPos;
26 }
27 else { clearInterval(scrollInterval); }
28 },10);
24} 29}
25 30
31
26function scroll(id) { 32function scroll(id) {
27 // document.getElementById(id).scrollIntoView(); 33// document.getElementById(id).scrollIntoView();
28 var el = document.getElementById(id); 34 scrollTo( document.getElementById(id).offsetTop, 500 );
29 var rect = el.getBoundingClientRect();
30 var top = rect.bottom + window.pageYOffset - el.ownerDocument.documentElement.clientTop;
31 scrollTo( document.body, top, 100 );
32} 35}
33 36
34function setClass(id, classes) { 37function setClass(id, classes) {