-
Notifications
You must be signed in to change notification settings - Fork 0
/
sortable.html
61 lines (53 loc) · 1.72 KB
/
sortable.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
<!-- <script src="https://code.jquery.com/jquery-3.6.3.min.js"></script>
<script defer src="https://code.jquery.com/ui/1.13.1/jquery-ui.min.js"></script> -->
<script src="/assets/cdn/jquery-3.6.3.min.js"></script>
<script defer src="/assets/cdn/1.13.1_jquery-ui.min.js"></script>
<div id="sortable-list">
<ul></ul>
</div>
<script>
var imageArray = [
"/assets/imgs/anime_girl.gif",
"/assets/imgs/cat_eyes.gif",
"/assets/imgs/hand.gif",
"/assets/imgs/hand_energy.gif",
]
$(document).ready(function () {
for (var i = 0; i < imageArray.length; i++) {
$("#sortable-list ul").append(`
<div>
<img src="${imageArray[i]}" alt="image${i + 1}">
<!-- <button class="delete-button">Delete</button> -->
</div>`);
}
$("#sortable-list ul").sortable({
items: "div",
handle: "img",
update: function (event, ui) {
var newImageArray = [];
$("#sortable-list ul div img").each(function () {
newImageArray.push($(this).attr("src"));
});
imageArray = newImageArray;
console.log(imageArray);
}
});
$(".delete-button").click(function () {
var imageToDelete = $(this).prev().attr("src");
var index = imageArray.indexOf(imageToDelete);
imageArray.splice(index, 1);
$(this).parent().remove();
});
});
</script>
<style>
ul div {
border: 1px solid gray;
margin: 0;
padding: 0;
border-radius: 5px;
}
img {
width: 100px
}
</style>