-
Notifications
You must be signed in to change notification settings - Fork 0
/
anime-js.html
49 lines (44 loc) · 1.14 KB
/
anime-js.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>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>Document</title>
<style>
.element {
background-color: red;
width: 50px;
height: 50px;
}
</style>
</head>
<body>
<div class="element"></div>
<!-- Anime js CDN -->
<script
src="https://cdnjs.cloudflare.com/ajax/libs/animejs/3.2.1/anime.min.js"
integrity="sha512-z4OUqw38qNLpn1libAN9BsoDx6nbNFio5lA6CuTp9NlK83b89hgyCVq+N5FdBJptINztxn1Z3SaKSKUS5UP60Q=="
crossorigin="anonymous"
referrerpolicy="no-referrer"
></script>
<script>
const element = document.querySelector('.element')
let clicked = false
element.addEventListener('click', () => {
if (clicked) {
anime({
targets: element,
translateX: 0,
})
clicked = false
return
}
anime({
targets: element,
translateX: 100,
})
clicked = true
})
</script>
</body>
</html>