-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathAddClassList.js
63 lines (48 loc) · 1.03 KB
/
AddClassList.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
function showHelloWorld(){
var helloWorldElement = document.getElementById('hello-world');
helloWorldElement.classList.remove('hide','fade-out');
helloWorldElement.classList.add('fade-in')
}
function hideHelloWorld(){
var helloWorldElement = document.getElementById('hello-world');
helloWorldElement.classList.add('fade-out');
helloWorldElement.classList.remove('fade-in');
setTimeout(function(){
helloWorldElement.classList.add('hide');
},2000) //Note that this interval matches the timing of CSS animation
}
body{
text-align:center;
}
#hello-world{
font-size:36px;
}
.hide{
display:none;
}
.fade-in{
animation: 2s fadeIn;
}
.fade-out{
animation: 2s fadeOut;
}
@keyframes fadeIn{
from{
opacity:0;
}
to{
opacity:1;
}
}
@keyframes fadeOut{
from{
opacity:1;
}
to{
opacity:0;
}
}
<div id="hello-world" class="hide">Hello World</div>
<br>
<button onclick="showHelloWorld()">Click Here To Fade In</button>
<button onclick="hideHelloWorld()">Click Here To Fade Out</button>