I am trying to follow this tutorial https://carouth.com/articles/flexible-carousel-with-alpinejs/ and copying the code line by line but still it is not working in my website. Here's my code -
<script>
declare const window: any;
window.carousel = function () {
return {
...,
scrollTo(element) {
const current = this.container;
if (!current || !element) return;
const nextScrollPosition =
element.offsetLeft +
element.getBoundingClientRect().width / 2 -
current.getBoundingClientRect().width / 2;
current.scroll({
left: nextScrollPosition,
behavior: 'smooth',
});
}
};
}
</script>
My website is completely not working and it is showing an error, the HTML and CSS is copied exactly the same