If you don't want to use any plugins or libraries and stick to vanilla JS then you'll need to repurpose the code that you've provided. If you think logically about what you're asking, the horizontal carousel depends on the container width and the child elements widths, and then moves them based on the left position.
So to translate that into vertical, look at the example code you already have and then translate the requirements. The vertical carousel depends on the container
height and the child elements
heights
, and then moves them based on the
top position.
Just a quick Google found for me:
html - How to create a vertical carousel using plain JavaScript and CSS - Stack Overflow[
^]