@@ -65,15 +65,16 @@ import Layout from '@/layouts/Layout.astro'
6565 * 480px - 1600px: Linear scale from 0.5 to 0.33
6666 * >= 1600px: 0.33
6767 */
68- function calculateImageScale() {
69- const width = window.innerWidth
70- const scale = Math.max(0.33, Math.min(0.5, 0.5 - (width - 480) * 0.17 / 1120))
71- return scale.toString()
68+ function calculateImageScale(width: number) {
69+ return Math.max(0.33, Math.min(0.5, 0.5 - (width - 480) * 0.17 / 1120))
7270}
7371
74- function updateImageScale() {
72+ function setupImageScale() {
73+ const width = window.innerWidth
74+ const scale = calculateImageScale(width)
7575 const imageStack = document.querySelector('.image-stack') as HTMLElement
76- imageStack?.style.setProperty('--image-scale', calculateImageScale())
76+
77+ imageStack?.style.setProperty('--image-scale', scale.toString())
7778}
7879
7980function handleClick(event: MouseEvent) {
@@ -83,7 +84,8 @@ function handleClick(event: MouseEvent) {
8384 target.closest('.image-item')?.classList.toggle('zoomed')
8485}
8586
86- updateImageScale( )
87- window.addEventListener('resize', updateImageScale )
87+ document.addEventListener('astro:page-load', () => setupImageScale() )
88+ window.addEventListener('resize', setupImageScale )
8889document.addEventListener('click', handleClick)
90+ setupImageScale()
8991</script >
0 commit comments