当前位置:网站首页>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
}
}
边栏推荐
- Deep neural network Summary
- SLAM|如何时间戳对齐?
- Deep learning mathematics foundation
- 文字编辑器 希望有错误的句子用红色标红,文字编辑器用了markdown
- 任职 22 年,PowerShell 之父将从微软离职:曾因开发 PowerShell 被微软降级过
- R language uses Cox of epidisplay package Display function obtains the summary statistical information of Cox regression model (risk rate HR, adjusted risk rate and its confidence interval, P value of
- 第一次去曼谷旅游怎么玩?这份省钱攻略请收好
- Yesterday, Alibaba senior wrote a responsibility chain model, and there were countless bugs
- Leetcode (81) -- search rotation sort array II
- [Yugong series] July 2022 go teaching course 001 introduction to go language premise
猜你喜欢
How to clean up discarded PVs and their corresponding folders
M2dgr: slam data set of multi-source and multi scene ground robot (ICRA 2022)
深度学习数学基础
Excel如何进行隔行复制粘贴
什么是云原生?这回终于能搞明白了!
[100 cases of JVM tuning practice] 02 - five cases of virtual machine stack and local method stack tuning
Hongmeng's fourth learning
Leetcode(81)——搜索旋转排序数组 II
What is cloud primordial? This time, I can finally understand!
How to enable the run dashboard function of idea
随机推荐
使用 Cheat Engine 修改 Kingdom Rush 中的金钱、生命、星
Competence of product manager
A simple PHP personal card issuing program v4.0
options should NOT have additional properties
Exness in-depth good article: dynamic series - Case Analysis of gold liquidity (V)
全链路数字化转型下,零售企业如何打开第二增长曲线
[daily question] first day
The difference between interceptor and filter
[fluent] dart data type (VaR data type | object data type)
[100 cases of JVM tuning practice] 01 - introduction of JVM and program counter
[100 cases of JVM tuning practice] 02 - five cases of virtual machine stack and local method stack tuning
Singapore summer tourism strategy: play Singapore Sentosa Island in one day
学生抖音宣传母校被吐槽“招生减章”,网友:哈哈哈哈哈哈
Mysql高级篇学习总结8:InnoDB数据存储结构页的概述、页的内部结构、行格式
UML 类图
如何优雅的写 Controller 层代码?
Industrial software lecture - core technology analysis of 3D CAD design software - the second lecture of the Forum
【JVM调优实战100例】03——JVM堆调优四例
什么是云原生?这回终于能搞明白了!
Slam | how to align timestamps?