How to create an infinity scroll? (Stack pages vertically)

I am using the “Stack all pages vertically” option and I would like it to seamlessly go back to the first page once it reaches the last page, creating an infinite scroll effect. I tried applying some JS code to achieve this, but it didn’t work. Does anyone have a code for this or any workaround to achieve this effect?