-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathHow-AutoAnimate-Works.html
60 lines (48 loc) · 1.85 KB
/
How-AutoAnimate-Works.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
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>How-AutoAnimate-Works</title>
</head>
<body>
<ul id="myList">
<li>Hello1</li>
<li>Hello2</li>
<li>Hello3</li>
<li>Hello4</li>
</ul>
<button onclick="changeOrder()">Change Order</button>
<button onclick="delete3th()">Delete 3th</button>
<script type="module">
import autoAnimate from "https://cdn.jsdelivr.net/npm/@formkit/auto-animate";
autoAnimate(document.getElementById("myList"));
</script>
<script>
const changeOrder = () => {
const myList = document.getElementById("myList");
const listItems = myList.getElementsByTagName("li");
// Convert HTMLCollection to array for easier manipulation
const itemsArray = Array.from(listItems);
// Reverse the order of the array
itemsArray.reverse();
// Append the items in the new order to the list
itemsArray.forEach(function (item) {
myList.appendChild(item);
});
};
const delete3th = () => {
const myList = document.getElementById("myList");
const listItems = myList.getElementsByTagName("li");
const itemsArray = Array.from(listItems);
console.log(itemsArray);
itemsArray.splice(2, 1);
console.log(itemsArray);
myList.innerHTML = "";
itemsArray.forEach(function (item) {
myList.appendChild(item);
});
};
</script>
</body>
</html>