diff options
Diffstat (limited to 'js')
-rw-r--r-- | js/abmahn.js | 31 |
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 | ||
15 | function scrollTo(element, to, duration) { | 15 | function 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 | |||
26 | function scroll(id) { | 32 | function 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 | ||
34 | function setClass(id, classes) { | 37 | function setClass(id, classes) { |