Skip to content

Commit aa3e6bd

Browse files
committed
Recalc screenHeight on resize
1 parent 14f1560 commit aa3e6bd

File tree

1 file changed

+11
-4
lines changed

1 file changed

+11
-4
lines changed

src/lib/FxParallax.svelte

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -16,27 +16,34 @@ let screenHeight = 0
1616
let stamp = 0
1717
let height = 100
1818
let offset = 0
19+
let normalized = 0
1920
2021
function entered(e) {
2122
stamp = scrollY + e.detail.boundingClientRect.top
2223
inview = true
2324
}
2425
26+
function resized() {
27+
screenHeight = window.screen.height
28+
}
29+
30+
$: normalized = Math.abs(factor - 1)
31+
2532
$: if (screenHeight && offsetHeight) {
26-
height = 100 + Math.abs(factor - 1) * (screenHeight / offsetHeight - 1) * 100
33+
height = 100 + normalized * (screenHeight / offsetHeight) * 100
2734
}
2835
2936
$: if (inview) {
30-
offset = Math.floor((scrollY - stamp) * Math.abs(factor - 1))
37+
offset = Math.floor((scrollY - stamp) * normalized)
3138
}
3239
3340
onMount(() => {
34-
screenHeight = window.screen.height
41+
resized()
3542
mounted = true
3643
})
3744
</script>
3845

39-
<svelte:window bind:scrollY />
46+
<svelte:window bind:scrollY on:resize={resized} />
4047

4148
<div
4249
class="wrap {classes}"

0 commit comments

Comments
 (0)