let data = [];
let currentRow = 0;
function getPositions(){
document.querySelectorAll('.row').forEach(row => {
let box = row.getBoundingClientRect();
data.push(box.top + pageYOffset);
});
}
getPositions();
document.addEventListener('wheel', event => {
event.preventDefault();
currentRow += event.deltaY > 0 ? 1 : -1;
if (currentRow<0) currentRow = 0;
if (currentRow>data.length-1) currentRow = data.length-1;
window.scrollTo({
top: data[currentRow],
behavior: 'smooth'
});
});
window.addEventListener('resize', () => {
getPositions();
});