-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathanimate3.html
49 lines (44 loc) · 1.32 KB
/
animate3.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
49
<!DOCTYPE html>
<html lang="en">
<head>
<title>Animation</title>
<style>
@keyframes move {
0% {
left: 0%;
}
50% {
left: 50%;
}
100% {
left: 0%;
}
}
h1 {
position: relative;
animation-name: move;
animation-duration: 3s;
animation-fill-mode: forwards;
animation-iteration-count: infinite;
}
</style>
<script>
document.addEventListener('DOMContentLoaded', () => {
const h1 = document.querySelector('h1');
// Stop animation initially
h1.style.animationPlayState = 'paused';
// Toggle animation on click
document.querySelector('button').onclick = () => {
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>