小编Tzu*_*Liu的帖子

使用setState的React滚动动画是不连贯的

似乎有用的setState是通过听取动画元素window.scrollY会产生非常不稳定的效果.

const scrollY = window.scrollY;

animation01: {
  transformY: (scrollY > breakPoint01) ? `translateY(200px)` : `translateY(0px)`,
},
Run Code Online (Sandbox Code Playgroud)

我最终得到了ref直接操作DOM 的解决方案,以避免波动效应......

const breakPoint00 = 1250
const breakPoint01 = breakPoint00 + 230
const animation01 = ReactDOM.findDOMNode(this.animation01)

if (scrollY > breakPoint00) {
  animation01.style.transform = `translateY(0px)`
} else (scrollY > breakPoint01) {
  animation01.style.transform = `translateY(200px)`
} 
Run Code Online (Sandbox Code Playgroud)

使用第一种解决方案时为什么会这么不稳定?这是在React中进行滚动动画的正确方法吗?

javascript scroll css-animations reactjs

5
推荐指数
1
解决办法
656
查看次数

标签 统计

css-animations ×1

javascript ×1

reactjs ×1

scroll ×1