A
A
Alex18239-232020-07-14 12:33:39
Browsers
Alex18239-23, 2020-07-14 12:33:39

Smooth scrolling safari?

Please tell me how to add to this method so that smooth scrolling works on safari as well, or maybe there is another solution.

function scrollTo(element) {
  window.scroll({
    left: 0,
    top: element.offsetTop,
    behavior: 'smooth'
  })
}

var contacts = document.querySelector('.contacts');
var footer = document.querySelector('.footer');

contacts.addEventListener('click', () => {
  scrollTo(footer);
});

Answer the question

In order to leave comments, you need to log in

1 answer(s)
V
Vladimir Proskurin, 2020-07-14
@Vlad_IT

Safari doesn't support behavior: 'smooth' or even scroll-behavior. You need to do it through JS polyfills (I won’t say a specific one, google it and see which one is more convenient, I use our team’s bike).
I hope I'm wrong, and someone will now offer a native solution, because. I already suffered with this safari, on iOS polyfills are wildly slow.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question