CLS
Cumulative Layout Shift https://web.dev/cls/
*ℹ️ Haven't tested a thing yet (finishing prioritized tasks atm, will be back for this one). Maybe the following list can bring some light or/and leads to more understanding about what's going on. In general it doesn't feel like a situation where I want to add heavy scripting, feels like there is a elegant way... (maybe it's even against the library paradigm, as we have target-selectors for sidemenu's (no scripting seem to be the approach here).
Here some first thoughts, guesses, experiences, investigations and links, and the IMO root cause why it happens..
Let's go:
- At firsrt glance it looks like anchor jumping by id, e.g.
#slide1
jumps to id="slide1"
element, native anchor jumps, so preventDefault will stop everything (let's exclude that)
Assuming the root cause are unknown width and heigh of the images (we need safeNumbers, percentage and vw,vh in safeNumbers no percentages etc. would probably work, but we need percentages
Check if animation targets top, right, bottom, left and if so, use:
`transform: translate() instead. Just comes to mind: DaisyUI and HeadlessUI is a great fit here.
Could eventually move the issue to loading time:
img { max-width: 100%; height: auto; }
...but don't we preload images in carousels anyway? if so, then the dimensions of the image is known – unknown width/height of the image as the root cause – and useLayoutEffect() is where you an calculate and set px values before the render is painted to the screen, right?
- Aspect Ratio Solution
good luck (will fix the typos another day ^^ when I pick up your end solution hehe)