-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathpratice3.html
More file actions
62 lines (48 loc) · 1.32 KB
/
Copy pathpratice3.html
File metadata and controls
62 lines (48 loc) · 1.32 KB
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
<!DOCTYPE html>
<head>
<title>Animation In JavaScript</title>
</head>
<body>
<button id="btn1" onclick="fadeOut()">FADE OUT</button>
<br>
<br>
<img id="img" src="images/heart.jpg" width= "500px">
<br>
<br>
<button id="btn2" onclick="fadeIn()">FADE IN</button>
</body>
<script type="text/javascript">
var opacity = 0;
var intervalID = 0;
function fadeOut(){
intervalID = setInterval(hide,100);
}
function hide()
{
var img = document.getElementById("img");
opacity = Number(window.getComputedStyle(img).getPropertyValue("opacity"));
if(opacity>0){
opacity = opacity-0.1;
img.style.opacity = opacity;
}
else{
clearInterval(intervalID);
}
}
// End of Fadeout Function
function fadeIn(){
intervalID = setInterval(show,200);
}
function show(){
var img = document.getElementById("img");
opacity = Number(window.getComputedStyle(img).getPropertyValue("opacity"));
if(opacity<1){
opacity = opacity + 0.1;
img.style.opacity = opacity;
}
else{
clearInterval(intervalID);
}
}
</script>
</html>