diff options
-rw-r--r-- | js/abmahn.js | 19 |
1 files changed, 17 insertions, 2 deletions
diff --git a/js/abmahn.js b/js/abmahn.js index 6b26e0b..af8f000 100644 --- a/js/abmahn.js +++ b/js/abmahn.js | |||
@@ -12,8 +12,23 @@ 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) { | ||
16 | if (duration <= 0) return; | ||
17 | var difference = to - element.scrollTop; | ||
18 | var perTick = difference / duration * 2; | ||
19 | |||
20 | setTimeout(function() { | ||
21 | element.scrollTop = element.scrollTop + perTick; | ||
22 | scrollTo(element, to, duration - 2); | ||
23 | }, 10); | ||
24 | } | ||
25 | |||
15 | function scroll(id) { | 26 | function scroll(id) { |
16 | document.getElementById(id).scrollIntoView(); | 27 | // document.getElementById(id).scrollIntoView(); |
28 | var el = document.getElementById(id); | ||
29 | var rect = el.getBoundingClientRect(); | ||
30 | var top = rect.bottom + window.pageYOffset - el.ownerDocument.documentElement.clientTop; | ||
31 | scrollTo( document.body, top, 100 ); | ||
17 | } | 32 | } |
18 | 33 | ||
19 | function setClass(id, classes) { | 34 | function setClass(id, classes) { |
@@ -21,7 +36,7 @@ function setClass(id, classes) { | |||
21 | } | 36 | } |
22 | 37 | ||
23 | function step0_cancel() { setClass('wrapper', 'stepcancel'); } | 38 | function step0_cancel() { setClass('wrapper', 'stepcancel'); } |
24 | function step0_done() { setClass('wrapper', 'step1'); scroll('head1'); } | 39 | function step0_done() { setClass('wrapper', 'step1'); scrollTo(document.body, 0, 100); } |
25 | function step1_done() { setClass('wrapper', 'step2'); scroll('head1'); } | 40 | function step1_done() { setClass('wrapper', 'step2'); scroll('head1'); } |
26 | function step2_done() { setClass('wrapper', 'step3'); scroll('head2'); } | 41 | function step2_done() { setClass('wrapper', 'step3'); scroll('head2'); } |
27 | function step3_done() { setClass('wrapper', 'step4'); scroll('head3'); } | 42 | function step3_done() { setClass('wrapper', 'step4'); scroll('head3'); } |