Я обнаружил проблему, связанную с scrollIntoView. Код, который я написал, работает на Firefox, но не на Chrome. Я не получаю никаких ошибок или чего-либо из консоли, поэтому я не знаю, в чем проблема. Как правильно запустить его на Chrome? Я хотел бы решить это в Vanilla JS
Вот мой код -> https://codepen.io/Rafi-R/pen/PLdvjO
const body = document.querySelector('body');
const links = document.querySelectorAll(".link");
let section = 0;
const scrollDirection = e => e.wheelDelta ? e.wheelDelta : -1 * e.deltaY;
const scrollToSection = e => {
e.preventDefault();
section =
scrollDirection(e) < 0
? (section + 1 >= links.length - 1 ? section = links.length - 1 : section + 1)
: (section - 1 <= 0 ? section = 0 : section - 1);
let element = document.querySelector(links[section].getAttribute("href"));
scrollToTheView(element);
}
const scrollToTheView = el => {
el.scrollIntoView({ behavior: 'smooth' });
console.log(el, links[section].getAttribute("href"), section)
}
body.addEventListener('wheel', scrollToSection, { passive: false });
Когда консоль codepen открыта console.log()
падает scrollIntoView({behavior: 'smooth'})
, поэтому прокрутка не работает.