首页 > 解决方案 > 在 Safari 上处理滚动动画的正确方法是什么

问题描述

在 Safari 中处理与滚动事件相关的动画的正确方法是什么(例如两个元素之间的滚动同步)?

我今天使用的解决方案可以在 Chrome 和 Firefox 上无缝运行,但在 Safari 中却非常滞后/跳跃。

总结一下代码,它是这样的:

element.addEventListener("scroll", () => {   
    window.requestAnimationFrame(){  
          otherElementWithScroll.scrollTop = element.scrollTop  
          otherElementWithHorizontalScroll.scrollLeft = element.scrollLeft  
    }   
})

otherElementWithScroll.addEventListener("scroll", () => {   
    window.requestAnimationFrame(){  
          element.scrollTop = otherElementWithScroll.scrollTop  
    }   
})  

otherElementWithHorizontalScroll.addEventListener("scroll", () => {   
    window.requestAnimationFrame(){  
          element.scrollLeft = otherElementWithHorizontalScroll.scrollLeft  
    }   
})

标签: scrollsafari

解决方案


推荐阅读