【发布时间】:2020-09-17 13:24:08
【问题描述】:
我做了一个进度条组件:
import React, {useState, useEffect} from "react";
var ProgressBar = ({percentage, duration}) => {
let [style, setStyle] = useState({
"position":"relative"
})
useEffect(()=>{
setStyle({
"top":"0px",
"position":"relative",
"height":"100%",
"backgroundColor": "lightblue",
"color": "lightgrey",
"left": "0px",
"transition": `width ${duration}s`,
"width": percentage+"%"
});
}, [])
var cntStyle = {
"display": "block",
"width": "150px",
"left":"0px",
"backgroundColor":"grey",
"height":"15px",
"position": "relative"
}
return (
<div className="progressbar-container"
style={cntStyle}>
<div className="progress" style={style}></div>
</div>
);
}
export default ProgressBar;
并像使用它
<ProgressBar
percentage="80"
duration="5" />
我想知道为什么过渡不起作用。直接显示80%的进度条。
【问题讨论】:
-
你能提供一个minimum reproducible example吗?
-
另外,在 useEffect 第二个参数(数组)中,传递百分比,以便在它发生变化时触发
标签: css transition