Skip to content

Commit c1c990a

Browse files
committed
add background to the async animation
1 parent 151a6b5 commit c1c990a

File tree

2 files changed

+33
-7
lines changed

2 files changed

+33
-7
lines changed

src/components/Stepper/index.scss

Lines changed: 20 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ $baseClass: 'vant-stepper';
2424
input {
2525
margin: 0px 2px;
2626
border-radius: 5px;
27+
font-size: 20px;
2728
border: none;
2829
display: flex;
2930
justify-content: center;
@@ -39,19 +40,32 @@ $baseClass: 'vant-stepper';
3940
border: none;
4041
font-weight: 100;
4142
}
42-
.loading{
43+
.load-background{
4344
display: inline-block;
4445
border: 4px solid rgba(0, 0, 0, 0.1);
45-
border-left-color: grey;
46+
border-left-color: white;
4647
border-radius: 50%;
47-
width: 65px;
48-
height: 65px;
48+
width: 35px;
49+
height: 35px;
4950
animation: donut-spin 1.2s linear infinite;
51+
position: relative;
52+
53+
opacity: 0;
54+
}
55+
.load{
56+
width: 85px;
57+
height: 85px;
5058
position: absolute;
51-
left: 47%;
52-
top: 35%;
59+
top: 30%;
60+
background-color: rgba(0, 0, 0, 0.836);
61+
display: flex;
62+
justify-content: center;
63+
align-items: center;
64+
border-radius: 10px;
65+
margin: auto;
5366
opacity: 0;
5467
}
68+
5569
}
5670

5771
button.#{$baseClass} {

src/components/Stepper/index.tsx

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@ export default function Stepper({
3737
const [plus, setPlus] = useState(false);
3838
const [Input, setInput] = useState(false);
3939
const animationDiv = document.getElementById('loading');
40+
const animationBackground = document.getElementById('loading-background');
4041

4142
const plusBtProps = {
4243
className: classnames(baseClass, [{ disabled }, { theme }]),
@@ -54,13 +55,16 @@ export default function Stepper({
5455
const handleIncrement = () => {
5556
if (loading) {
5657
ReactDOM.findDOMNode(animationDiv).style.opacity = 1;
58+
ReactDOM.findDOMNode(animationBackground).style.opacity = 1;
5759
const handlePlus = () => {
5860
if (step) {
5961
setValue(value + step);
6062
ReactDOM.findDOMNode(animationDiv).style.opacity = 0;
63+
ReactDOM.findDOMNode(animationBackground).style.opacity = 0;
6164
} else {
6265
setValue(value + 1);
6366
ReactDOM.findDOMNode(animationDiv).style.opacity = 0;
67+
ReactDOM.findDOMNode(animationBackground).style.opacity = 0;
6468
}
6569
};
6670

@@ -75,13 +79,17 @@ export default function Stepper({
7579
const canMinus = value - step;
7680
if (loading) {
7781
ReactDOM.findDOMNode(animationDiv).style.opacity = 1;
82+
ReactDOM.findDOMNode(animationBackground).style.opacity = 1;
83+
7884
const handleMinus = () => {
7985
if (step) {
8086
setValue(value - step);
8187
ReactDOM.findDOMNode(animationDiv).style.opacity = 0;
88+
ReactDOM.findDOMNode(animationBackground).style.opacity = 0;
8289
} else {
8390
setValue(value - 1);
8491
ReactDOM.findDOMNode(animationDiv).style.opacity = 0;
92+
ReactDOM.findDOMNode(animationBackground).style.opacity = 0;
8593
}
8694
};
8795
setTimeout(handleMinus, 2000);
@@ -197,7 +205,11 @@ export default function Stepper({
197205
<button onClick={handleIncrement} {...plusBtProps} disabled={plus}>
198206
+
199207
</button>
200-
{loading && <div id='loading' className='loading' />}
208+
{loading && (
209+
<div id='loading-background' className='load'>
210+
<div id='loading' className='load-background' />
211+
</div>
212+
)}
201213
</div>
202214
);
203215
}

0 commit comments

Comments
 (0)