Here is a jQuery example for a progress bar animation. and I want this feature in Reactjs without jQuery. How to implement this feature.
问问题
3619 次
2 回答
1
这是如何做到的。
制作 2 个 div(容器,进行中的一个),您可以根据状态更改更改进行中 div 的高度。
const styled = styled.default;
const Bar = styled.div`
position: relative;
height: 500px;
width: 100%;
border-radius: 3px;
border: 1px solid #ccc;
margin: 1rem auto;
`
const Fill = styled.div`
background: #0095da;
width: 100%;
border-radius: inherit;
transition: height 0.2s ease-in;
height: ${(props) => `${props.percentual}%`};
`
const ProgressBar = ({ percentage }) => {
return (
<div>
<Bar>
<Fill percentage={percentage} />
</Bar>
</div>
);
}
ReactDOM.render(<ProgressBar percentage={you state for progress percentage} />, document.getElementById('bar'));
你甚至不需要为此做出反应。 https://www.w3schools.com/howto/tryit.asp?filename=tryhow_js_progressbar_label_js
于 2018-12-01T17:54:01.287 回答
1
我希望你仍然对这个问题感兴趣。我只是修补 react-spring,我真的很喜欢它。React 恕我直言,最好的动画库。
您可以使用 Spring 组件创建一个整洁的组件。它将始终为 Spring 组件的 to 属性设置动画。第一次来自 from 属性的 from 值。
import React from "react";
import { Spring } from "react-spring";
const VerticalProgress = ({ progress }) => {
return (
<Spring from={{ percent: 0 }} to={{ percent: progress }}>
{({ percent }) => (
<div className="progress vertical">
<div style={{ height: `${percent}%` }} className="progress-bar">
<span className="sr-only">{`${progress}%`}</span>
</div>
</div>
)}
</Spring>
);
};
export default VerticalProgress;
于 2019-01-08T08:13:55.017 回答