css - ReactJS — 如何使用 createRef() 修改 CSS 属性?
问题描述
我试图在 FullPageJS 中更改页面更改时将垂直移动添加到堆叠标题列表中。我完全没有错误,但行动没有发生。我的猜测是我尝试使用元素 ref 修改 CSS 属性转换是错误的。任何人都可以发现下面的代码有问题吗?
先感谢您。
反应
componentDidMount() {
titleWidth = this.title.current.clientHeight
titleHeight = this.title.current.clientHeight
this.mask.current.css = {
height: titleHeight + "px",
width: titleWidth + "px",
}
this.frame.current.css = { top: titleHeight + "px" }
}
onLeave(origin, destination, direction) {
console.log("Leaving section " + origin.index)
// Actions not working
if (direction == "down") {
this.frame.current.style.transition = { top: "-=" + titleHeight }
} else if (direction == "up") {
this.frame.current.style.transition = { top: "+=" + titleHeight }
}
}
HTML
<div id="wrapper--frame" className="flex justify-center">
<div ref={this.mask} id="mask" className="w-5/6 overflow-hidden">
<div ref={this.frame} id="frame">
<div ref={this.title} className="text-p frame--title ">
One
</div>
<div ref={this.title} className="text-p frame--title ">
Two
</div>
<div ref={this.title} className="text-p frame--title ">
Three
</div>
<div ref={this.title} className="text-p frame--title ">
Four
</div>
</div>
</div>
</div>
解决方案
推荐阅读
- r - 分配全局/反应变量
- java - 如何等待所有按钮点击功能完成
- swift - 为什么我在 draw 中创建的 CAShapeLayer 没有成功设置动画?
- python - 如果两列具有相同的字符串或列为空,则从 python 中的 postgres 表中获取行
- http - Flutter 中的 API 访问问题
- javascript - 即使输入了错误的凭据 Passport.js 登录功能也不会产生任何错误并使用户通过身份验证
- bash - 如何发送 1kk post http 请求。最快的方法是什么?
- python - 有没有办法优化熊猫中连接表的创建?
- javascript - 无法更新 React Js 表单中的状态值
- jquery - 错误消息的顺序以反映 Jquery 验证中输入字段的顺序