javascript - window.scrollto和scrollIntoView在ios中滚动不顺畅

标签 javascript html ios css frontend

我有一个固定的顶栏,当我点击它时,页面会滚动到相应的部分。然而,它在我的 iphone8(ios13) 中滚动不顺畅,而在 chrome 和 android 中则完美运行。 我尝试使用scrollIntoview,但它也不起作用。 这是代码

scrollToAnchor = tabIndex => {
      window.scrollTo({
        top: this.state.tabListTop[tabIndex] - 76,
        behavior: 'smooth'
    })
  }

最佳答案

您可以通过老式方式实现此目的:

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);
}

关于javascript - window.scrollto和scrollIntoView在ios中滚动不顺畅,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/59644642/

相关文章:

javascript - 像 rails 这样的部分只在纯 javascript 中完成,并且纯粹在客户端。 - IE。没有服务器

iphone - 面向方面的 Objective-C 库?

jquery - 适用于触摸屏设备的最佳 jQuery Swipe 滑动

html - 底部边框小于宽度的标题

html - 一页网站导航栏不工作

html - 如何使一个div填充外部div的整个高度并在中心垂直对齐?

ios - Xcode 9 导出选项如何指定配置文件

javascript - 将脚本包装在调用函数中

javascript - 如何以现代 Angular 将事件从孙辈发送到祖 parent ?

javascript - React/redux 汉堡菜单无法打开