当前位置:网站首页>Progress progress bar
Progress progress bar
2022-07-02 19:01:00 【Zang Xiaochuan】
design sketch

Main
import {
useState } from 'react';
import Progress from './Progress'
const contentStyle = {
margin: '200px auto',
width: '300px'
};
const index = () =>
{
const [count, setCount] = useState(50)
return (
<div style={
contentStyle} >
<Progress percent={
count} unSelectedColor={
'#000'} strokeColor={
{
from: 'rgb(161, 29, 102)',
to: 'rgb(83, 177, 36)',
}} />
</div>
);
};
export default index
JS
import {
useState, useRef } from 'react';
import styles from './style.less'
const index = ({
percent, unSelectedColor, strokeColor }) =>
{
// ! percentage
const [count, setCount] = useState(percent)
const myRef = useRef(null)
const bgDown = (e) =>
{
e = e || window.event
const {
nativeEvent: {
offsetX } } = e
setCount(Math.round(offsetX / myRef.current.clientWidth * 100))
// ! If it is triggered by the current node Beyond this dom Will not trigger continuously The experience effect is not good therefore Can be replaced by document
myRef.current.addEventListener('mousemove', fn)
// ! In this case Even beyond this DOM This function will still be triggered
// document.addEventListener('mousemove', fn)
function fn (e)
{
// ! offsetX Current mouse click position
const {
offsetX } = e
// ? round integer You can remove this if you don't need it Math.round
let newCount = Math.round(offsetX / myRef.current.clientWidth * 100)
newCount <= 100 ? setCount(newCount) : setCount(100)
}
document.addEventListener('mouseup', (() =>
{
// ! Replace with document And cancel the click event
myRef?.current?.removeEventListener('mousemove', fn);
// document.removeEventListener('mousemove', fn);
}))
}
return (
<div className={
`${
styles.progress} ${
styles.progress_line} ${
styles.progress_show_info}`}>
<div className={
styles.progress_outer}>
<div id='inner' ref={
myRef} style={
{
backgroundColor: unSelectedColor && unSelectedColor }} onMouseDown={
bgDown} className={
styles.progress_inner}>
<div style={
{
width: `${
count}%`, backgroundImage: `linear-gradient(to right, ${
strokeColor['from']}, ${
strokeColor['to']}` }} className={
styles.progress_bg}>
<span>{
count}</span>
</div>
</div>
</div>
<span className={
styles.progress_text}>{
`${
count}%`}</span>
</div>
);
};
export default index
CSS
.progress {
box-sizing: border-box;
margin: 0;
padding: 0;
color: rgba(0, 0, 0, 0.85);
font-size: 14px;
font-variant: tabular-nums;
line-height: 1.5715;
list-style: none;
font-feature-settings: 'tnum', "tnum";
display: inline-block;
}
.progress_line {
position: relative;
width: 100%;
font-size: 14px;
}
.progress_outer {
display: inline-block;
width: 100%;
margin-right: 0;
padding-right: 0;
margin-right: calc(-2em - 8px);
padding-right: calc(2em + 8px);
}
.progress_inner {
position: relative;
display: inline-block;
width: 100%;
// overflow: hidden;
vertical-align: middle;
background-color: #f5f5f5;
border-radius: 100px;
// ! You can add a padding effect
// padding: 3px;
}
.progress_bg {
position: relative;
background-color: #1890ff;
border-radius: 100px;
transition: all 0.4s cubic-bezier(0.08, 0.82, 0.17, 1) 0s;
height: 8px;
animation: progress-info 3s ease-out;
&::before {
position: absolute;
top: 0;
right: 0;
bottom: 0;
left: 0;
background: #fff;
border-radius: 10px;
opacity: 0;
animation: progress-active 2.4s cubic-bezier(0.23, 1, 0.32, 1) infinite;
content: '';
}
&::after {
content: "";
display: inline-block;
position: absolute;
right: -4px;
top: -8px;
width: 0;
height: 0;
border-left: 4px solid transparent;
border-right: 4px solid transparent;
border-top: 3px solid #fff;
}
span {
display: inline-block;
position: absolute;
right: 6px;
top: -20px;
}
.progress-status-active .ant-progress-bg::before {
position: absolute;
top: 0;
right: 0;
bottom: 0;
left: 0;
background: #fff;
border-radius: 10px;
opacity: 0;
animation: progress-active 2.4s cubic-bezier(0.23, 1, 0.32, 1) infinite;
content: '';
}
@keyframes progress-active {
0% {
transform: translateX(-100%) scaleX(0);
opacity: 0.1;
}
20% {
transform: translateX(-100%) scaleX(0);
opacity: 0.5;
}
100% {
transform: translateX(0) scaleX(1);
opacity: 0;
}
}
}
@keyframes progress-info {
0% {
width: 0;
}
}
.progress_text {
display: inline-block;
width: 2em;
margin-left: 8px;
color: rgba(0, 0, 0, 0.85);
font-size: 1em;
line-height: 1;
white-space: nowrap;
text-align: left;
vertical-align: middle;
word-break: normal;
}
design sketch

JS
import {
useState, useEffect } from 'react';
import styles from './style.less'
const index = () =>
{
const [count, setCount] = useState(0)
useEffect(() =>
{
setTimeout(() =>
{
setCount(80)
}, 1000);
}, [])
return (
<div className={
styles.container}>
<div className={
styles.progress}>
<div style={
{
width: `${
count}%` }} className={
styles.progress_bg}></div>
<span> I'll set you monkey </span>
</div>
</div>
);
};
export default index
CSS
body {
margin: 300px;
background-color: pink;
width: 300px;
}
.progress {
display: inline-block;
width: 200px;
height: 3px;
background-color: hsla(0, 0%, 100%, .2);
vertical-align: middle;
.progress_bg {
position: relative;
background-color: #fff;
height: 3px;
// ! The excessive effect of line expansion
transition: all 3s;
// ! The width of the line
width: 30%;
&::after {
content: "";
display: inline-block;
position: absolute;
right: -4px;
top: -8px;
width: 0;
height: 0;
border-left: 4px solid transparent;
border-right: 4px solid transparent;
border-top: 3px solid #fff;
}
}
span {
font-size: 12px;
color: hsla(0, 0%, 100%, .4);
opacity: 0;
position: relative;
top: -5px;
letter-spacing: .5em;
transition: all .3s
}
&:hover span {
opacity: 1;
top: 0
}
}
边栏推荐
- 【愚公系列】2022年07月 Go教学课程 001-Go语言前提简介
- Leetcode (81) -- search rotation sort array II
- Google's official response: we have not given up tensorflow and will develop side by side with Jax in the future
- R语言使用epiDisplay包的lrtest函数对多个glm模型(logisti回归)执行似然比检验(Likelihood ratio test)对比两个模型的性能是否有差异、广义线性模型的似然比检
- LightGroupButton* sender = static_ cast<LightGroupButton*>(QObject::sender());
- Stratégie touristique d'été de Singapour: un jour pour visiter l'île de San taosha à Singapour
- Responses of different people in technology companies to bugs | daily anecdotes
- Meta universe chain game system development (logic development) - chain game system development (detailed analysis)
- 深度神经网络总结
- Crypto usage in nodejs
猜你喜欢

深度学习数学基础

LightGroupButton* sender = static_ cast<LightGroupButton*>(QObject::sender());

谷歌官方回应:我们没有放弃TensorFlow,未来与JAX并肩发展

Leetcode (81) -- search rotation sort array II

The text editor hopes to mark the wrong sentences in red, and the text editor uses markdown

Responses of different people in technology companies to bugs | daily anecdotes
![[100 cases of JVM tuning practice] 01 - introduction of JVM and program counter](/img/c4/3bba96fda92328704c2ddd929dcdf6.png)
[100 cases of JVM tuning practice] 01 - introduction of JVM and program counter

yolov3 训练自己的数据集之生成train.txt

Deep learning mathematics foundation

Tips for material UV masking
随机推荐
SLAM|如何时间戳对齐?
Detailed explanation of cjson usage
拦截器与过滤器的区别
How to delete the border of links in IE? [repeat] - how to remove borders around links in IE? [duplicate]
2022软件工程期末考试 回忆版
Concepts and differences of PR curve and ROC curve
R language ggplot2 visualization: gganimate package creates dynamic histogram animation (GIF) and uses transition_ The States function displays a histogram step by step along a given dimension in the
[Yugong series] July 2022 go teaching course 001 introduction to go language premise
How to play when you travel to Bangkok for the first time? Please keep this money saving strategy
[daily question] the next day
SAP S/4HANA OData Mock Service 介绍
迷你高尔夫球场:伦敦休闲旅游好去处
Radian to angle, angle to radian in MATLAB
第一次去曼谷旅游怎么玩?这份省钱攻略请收好
链游系统开发(Unity3D链游开发详情)丨链游开发成熟技术源码
AI开发调试系列第二弹:多机分布式调测探索之旅
R language dplyr package Na_ The if function converts the control in the vector value into the missing value Na, and converts the specified content into the missing value Na according to the mapping r
R language ggplot2 visualization: visualize the line chart and add customized X-axis label information to the line chart using labs function
How to clean up discarded PVs and their corresponding folders
IPtable port redirection masquerade[easy to understand]