【问题标题】:window.scrollto and scrollIntoView not scroll smoothly in ioswindow.scrollto 和 scrollIntoView 在 ios 中不能平滑滚动
【发布时间】:2020-01-08 11:15:27
【问题描述】:

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

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

【问题讨论】:

    标签: javascript html ios css frontend


    【解决方案1】:

    你可以用老式的方式实现这一点:

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

    【讨论】:

      【解决方案2】:

      scrollTo 不支持 iOS Safari 中的选项。 以下是 CanIUse 的当前状态:https://caniuse.com/#search=scrollto

      【讨论】:

        猜你喜欢
        • 2017-02-14
        • 2020-10-17
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2020-02-20
        • 1970-01-01
        • 1970-01-01
        • 2022-01-03
        相关资源
        最近更新 更多