when i add its not delay then removes it. and its delay, but what should i do to make this button have href to click and delay then joining other pages (i’m newbie)
conclude that I need when I click and reload 3 seconds to join other pages I do. I tried many things but it didn’t work. I’m very worried about my problem.
Thanks you all.
JavaScript
x
89
89
1
.button {
2
position: relative;
3
padding: 1px 20px;
4
background-color: #4bb34e;
5
border: none;
6
outline: none;
7
border-radius: 2px;
8
width: 100px;
9
cursor: pointer;
10
line-height: 1.33;
11
}
12
13
.button span {
14
cursor: pointer;
15
display: inline-block;
16
position: relative;
17
transition: 0.5s;
18
}
19
20
.button span:after {
21
content: '0bb';
22
position: absolute;
23
opacity: 0;
24
top: 0;
25
right: -10px;
26
transition: 0.5s;
27
}
28
29
.button:hover span {
30
padding-right: 20px;
31
}
32
33
.button:hover span:after {
34
opacity: 1;
35
right: 0;
36
}
37
38
.button:active {
39
background: #4CAF50;
40
}
41
42
.button__text {
43
font: bold 16px "Quicksand", san-serif;
44
color: #ffffff;
45
position: absolute;
46
top: 0;
47
left: 0;
48
right: 0;
49
bottom: 0;
50
margin: auto;
51
border: 4px solid transparent;
52
border-radius: 50%;
53
}
54
55
.button--loading .button__text {
56
visibility: hidden;
57
opacity: 0;
58
}
59
60
.button--loading::after {
61
content: "";
62
position: absolute;
63
width: 16px;
64
height: 16px;
65
top: 0;
66
left: 0;
67
right: 0;
68
bottom: 0;
69
margin: auto;
70
border: 4px solid transparent;
71
border-top-color: #ffffff;
72
border-radius: 50%;
73
animation: button-loading-spinner 1s ease infinite;
74
}
75
76
input,
77
p {
78
font: 17px Calibri;
79
padding: 3px 5px;
80
}
81
82
@keyframes button-loading-spinner {
83
from {
84
transform: rotate(0turn);
85
}
86
to {
87
transform: rotate(1turn);
88
}
89
}
JavaScript
1
2
1
<button type="button" class="button" onclick="setTimeout(() => this.classList.toggle('button--loading'), 1500)">
2
<span class="button__text">Submit</span></button>
Advertisement
Answer
I use jquery to fix this, try this method:
JavaScript
1
7
1
$('.button').click(function() {
2
$('.button').addClass("button--loading");
3
setTimeout(function() {
4
location.href = 'https://stackoverflow.com/'; // replace your URL
5
}, 3000);
6
7
});
JavaScript
1
89
89
1
.button {
2
position: relative;
3
padding: 1px 20px;
4
background-color: #4bb34e;
5
border: none;
6
outline: none;
7
border-radius: 2px;
8
width: 100px;
9
cursor: pointer;
10
line-height: 1.33;
11
}
12
13
.button span {
14
cursor: pointer;
15
display: inline-block;
16
position: relative;
17
transition: 0.5s;
18
}
19
20
.button span:after {
21
content: '0bb';
22
position: absolute;
23
opacity: 0;
24
top: 0;
25
right: -10px;
26
transition: 0.5s;
27
}
28
29
.button:hover span {
30
padding-right: 20px;
31
}
32
33
.button:hover span:after {
34
opacity: 1;
35
right: 0;
36
}
37
38
.button:active {
39
background: #4CAF50;
40
}
41
42
.button__text {
43
font: bold 16px "Quicksand", san-serif;
44
color: #ffffff;
45
position: absolute;
46
top: 0;
47
left: 0;
48
right: 0;
49
bottom: 0;
50
margin: auto;
51
border: 4px solid transparent;
52
border-radius: 50%;
53
}
54
55
.button--loading .button__text {
56
visibility: hidden;
57
opacity: 0;
58
}
59
60
.button--loading::after {
61
content: "";
62
position: absolute;
63
width: 16px;
64
height: 16px;
65
top: 0;
66
left: 0;
67
right: 0;
68
bottom: 0;
69
margin: auto;
70
border: 4px solid transparent;
71
border-top-color: #ffffff;
72
border-radius: 50%;
73
animation: button-loading-spinner 1s ease infinite;
74
}
75
76
input,
77
p {
78
font: 17px Calibri;
79
padding: 3px 5px;
80
}
81
82
@keyframes button-loading-spinner {
83
from {
84
transform: rotate(0turn);
85
}
86
to {
87
transform: rotate(1turn);
88
}
89
}
JavaScript
1
4
1
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
2
3
<button type="button" class="button">
4
<span class="button__text">Submit</span></button>