Code:


Key points in this implementation

<motion.div drag onViewportBoxUpdate={(box, delta) => {...}}>
const targetIndex = Math.round(delta.y.translate / height 
                     - 0.2 * Math.sign(delta.y.translate) // prevent infinite loop
                    ) + index