-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathindex.html
94 lines (90 loc) · 2.74 KB
/
index.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
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>Spring Chain Example</title>
<style>
.animate-div {
width: 100px;
height: 100px;
background-color: blue;
position: absolute;
border-radius: 0.5rem;
box-shadow: 0 0 10px rgba(0, 0, 0, 0.5);
top: 100px;
left: 100px;
}
</style>
</head>
<body>
<div class="animate-div"></div>
<button id="stop">Stop Animations</button>
<button id="start">Continue Animations</button>
<script>
document.addEventListener("DOMContentLoaded", () => {
const div = document.querySelector(".animate-div")
const stopButton = document.getElementById("stop")
const start = document.getElementById("start")
function animate() {
// Rotation animation
div.motion({
spring: {
stiffness: 20, // Lower stiffness means more springy
damping: 5, // Lower damping means more bouncy
mass: 1, // Lower mass means more bouncy
},
rotate: 360, // Rotate 360 degrees
delay: 500, // Delay (x)ms before starting this animation
})
// Scale animation
div.motion({
spring: {
stiffness: 20,
damping: 5,
mass: 1,
},
scale: 2, // Scale to 2x
})
// chain animation
div
.motion({
spring: {
stiffness: 20, // Lower stiffness means more springy
damping: 5, // Lower damping means more bouncy
mass: 1, // Lower mass means more bouncy
},
x: 360, // Move 360px to the right
})
.motion({
spring: {
stiffness: 20,
damping: 5,
mass: 1,
},
y: 360, // Move 360px down
})
.motion({
scale: 1, // Scale back to 1x
rotate: 360, // Rotate 360 degrees
})
.motion({
width: 200, // Increase width to 200px
height: 200, // Increase height to 200px
backgroundColor: "red", // Change background color to red
})
}
animate()
stopButton.addEventListener("click", () => {
// stop animation
div.stopMotion()
})
start.addEventListener("click", () => {
// start animation
animate()
})
})
</script>
<script src="./node_modules/spring-chain/dist/springChain.umd.js"></script>
</body>
</html>