Reputation: 81
I have a fixed top bar when I click it, the page will scroll to the corresponding part. However, it doesn't scroll smoothly in my iphone8(ios13), while it works perfectly in chrome and android. I tried to use scrollIntoview, but it doesn't work either. Here is the code
scrollToAnchor = tabIndex => {
window.scrollTo({
top: this.state.tabListTop[tabIndex] - 76,
behavior: 'smooth'
})
}
Upvotes: 3
Views: 852
Reputation: 5566
You can achieve this in the old fashioned way:
smoothScroll = (height) => {
// "height" is the Height you want to scroll to
var i = 10;
var int = setInterval(function() {
window.scrollTo(0, i);
i += 10;
if (i >= height ) clearInterval(int);
}, 20);
}
Upvotes: 1
Reputation: 209
scrollTo
does not support options in iOS Safari.
Here is the current status from CanIUse: https://caniuse.com/#search=scrollto
Upvotes: 1