Skip to content

Commit

Permalink
ZHeader - optimize
Browse files Browse the repository at this point in the history
  • Loading branch information
vhtmui_5600g committed Nov 19, 2024
1 parent f48679e commit 73cd177
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 8 deletions.
25 changes: 17 additions & 8 deletions src/lib/ZHeader/ZHeader.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -209,15 +209,26 @@
saveCfg();
}
});
let timer;
</script>

<svelte:window
onresize={() => {
const bodyWidth = document.body.clientWidth;
snippets.forEach((snippet) => {
const base = get(snippet.start);
autoAdjust(base, bodyWidth, snippet);
});
if (timer) {
clearTimeout(timer);
}
timer = setTimeout(() => {
const bodyWidth = document.body.clientWidth;
let copy = snippets.map((s) => s).sort((a, b) => get(a.start) - get(b.start));
for (let i = 0; i < copy.length; i++) {
if (i % 2 === 0 || i === copy.length - 1) {
const base = get(copy[i].start);
autoAdjust(base, bodyWidth, copy[i]);
}
}
saveCfg();
}, 501);
}}
/>

Expand Down Expand Up @@ -253,8 +264,6 @@
}
window.addEventListener('pointermove', seek);

// Save config after motion end.
const duration = 0.5;
// Tie up loose ends while pointerup.
window.addEventListener(
'pointerup',
Expand All @@ -267,7 +276,7 @@
let b = (e3.clientX - gap) / bodyWidth;
autoAdjust(b, bodyWidth, snippet);
// Current target's start position in Percentage.
saveCfg(duration * 1001);
saveCfg(1001);
},
{ once: true }
);
Expand Down
1 change: 1 addition & 0 deletions src/routes/+layout.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -285,6 +285,7 @@
padding: 0;
margin: 0;
width: 100%;
max-width: 100%;
text-rendering: optimizeSpeed;
}
}
Expand Down

0 comments on commit 73cd177

Please sign in to comment.