From 46f586a803fbd856dba4daf7942cc05c1247cb88 Mon Sep 17 00:00:00 2001 From: fadhlu Date: Wed, 17 Mar 2021 12:04:01 +0700 Subject: [PATCH] Change sroll method to findPos --- src/routes/calculator/index.svelte | 49 +++++++++++++++++++++--------- 1 file changed, 35 insertions(+), 14 deletions(-) diff --git a/src/routes/calculator/index.svelte b/src/routes/calculator/index.svelte index be019bed..62645bc0 100644 --- a/src/routes/calculator/index.svelte +++ b/src/routes/calculator/index.svelte @@ -16,6 +16,7 @@ let weaponCalc; let characterCalc; + let resinCalc; function openHowTo() { openModal( @@ -28,16 +29,22 @@ ); } - export function scroll(type) { - const elementPosition = - type === 'character' ? characterCalc.getBoundingClientRect().top : weaponCalc.getBoundingClientRect().top; - const headerOffset = 80; - const offsetPosition = elementPosition - headerOffset; + export function findPos(id) { + let node = document.getElementById(id); + let curtop = 0; + let curtopscroll = 0; + let headerOffset = 40; + if (node.offsetParent) { + do { + curtop += node.offsetTop; + curtopscroll += node.offsetParent ? node.offsetParent.scrollTop : 0; + } while ((node = node.offsetParent)); - window.scrollTo({ - top: offsetPosition, - behavior: 'smooth', - }); + window.scrollTo({ + top: curtop - curtopscroll - headerOffset, + behavior: 'smooth', + }); + } } @@ -60,14 +67,15 @@
- +

@@ -76,14 +84,19 @@

- +

@@ -91,7 +104,15 @@

-
+
+