Skip to content

Commit 97524f3

Browse files
committed
refactor(transition): set style properties directly
1 parent 3a1247e commit 97524f3

File tree

1 file changed

+12
-4
lines changed

1 file changed

+12
-4
lines changed

src/lib/headroom/index.svelte

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,6 @@
2222
let lastY = 0
2323
let atTop = true
2424
let atBottom = false
25-
let style = `--duration:${duration}; --easing:${easing};`
2625
2726
validate({ duration, easing, tolerance, toleranceDown, toleranceUp, offset, offsetTop, offsetBottom })
2827
@@ -37,7 +36,7 @@
3736
})
3837
3938
function deriveClass(y = 0, scrolled = 0) {
40-
if (y < offsetTop) return 'pin'
39+
if (y < offsetTop) return headerClass
4140
const up = scrolled > 0
4241
if (!scrolled
4342
|| (
@@ -55,6 +54,14 @@
5554
return result
5655
}
5756
57+
/**
58+
* @param {HTMLDivElement} node
59+
*/
60+
function transitionSettings(node) {
61+
node.style.transitionDuration = duration
62+
node.style.transitionTimingFunction = easing
63+
}
64+
5865
$: {
5966
headerClass = updateClass(y)
6067
atTop = y <= offsetTop
@@ -67,7 +74,7 @@
6774
</script>
6875
<svelte:window bind:scrollY={y} />
6976
<div
70-
{style}
77+
use:transitionSettings
7178
class={headerClass}
7279
class:bottom
7380
class:atTop
@@ -78,14 +85,15 @@
7885
class:hideAtBottom
7986
>
8087
<slot />
88+
8189
</div>
8290

8391
<style>
8492
div {
8593
position: fixed;
8694
width: 100%;
8795
top: 0;
88-
transition: transform var(--duration, 300ms) var(--easing, linear);
96+
transition: transform 300ms linear;
8997
}
9098
.bottom {
9199
top: auto;

0 commit comments

Comments
 (0)