在Safari上处理滚动动画的正确方法是什么

时间:2019-05-25 22:50:50

标签: scroll 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  
    }   
})

0 个答案:

没有答案