-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathanimate.html
48 lines (43 loc) · 1.3 KB
/
animate.html
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
<!DOCTYPE html>
<html lang=""en>
<head>
<title>Animate</title>
<style>
@keyframes move {
0% {
left: 0%;
}
50% {
left: 50%;
}
100% {
left: 0%;
}
}
h1 {
position: relative;
animation-name: move;
animation-duration: 2s;
animation-fill-mode: forwards;
animation-iteration-count: infinite;
}
</style>
<script>
document.addEventListener('DOMContentLoaded', () => {
const h1 = document.querySelector('h1');
h1.style.animationPlayState = 'paused';
document.querySelector('button').onclick = function() {
if (h1.style.animationPlayState === 'paused') {
h1.style.animationPlayState = 'running';
} else {
h1.style.animationPlayState = 'paused';
};
};
});
</script>
</head>
<body>
<button>Click Here!</button>
<h1>Welcome!</h1>
</body>
</html>