sortablejs_nested_list.html
· 1.4 KiB · HTML
Brut
<!DOCTYPE html>
<html lang="zh-TW">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>SortableJS 巢狀清單</title>
<style>
.nested-list {
list-style: none;
padding-left: 20px;
}
.nested-item {
padding: 8px;
margin: 5px;
background: #fff;
border: 1px solid #ddd;
cursor: grab;
}
.nested-item:hover {
background: #f0f0f0;
}
</style>
</head>
<body>
<h2>可拖曳巢狀清單</h2>
<ul id="nested-list" class="nested-list">
<li class="nested-item">項目 1
<ul class="nested-list">
<li class="nested-item">子項目 1.1</li>
<li class="nested-item">子項目 1.2</li>
</ul>
</li>
<li class="nested-item">項目 2</li>
<li class="nested-item">項目 3
<ul class="nested-list">
<li class="nested-item">子項目 3.1</li>
</ul>
</li>
</ul>
<script src="https://cdn.jsdelivr.net/npm/sortablejs@1.15.0/Sortable.min.js"></script>
<script>
new Sortable(document.getElementById('nested-list'), {
animation: 150,
group: 'nested',
fallbackOnBody: true,
swapThreshold: 0.65
});
document.querySelectorAll('.nested-list').forEach(list => {
new Sortable(list, {
animation: 150,
group: 'nested',
fallbackOnBody: true,
swapThreshold: 0.65
});
});
</script>
</body>
</html>
| 1 | <!DOCTYPE html> |
| 2 | <html lang="zh-TW"> |
| 3 | <head> |
| 4 | <meta charset="UTF-8"> |
| 5 | <meta name="viewport" content="width=device-width, initial-scale=1.0"> |
| 6 | <title>SortableJS 巢狀清單</title> |
| 7 | <style> |
| 8 | .nested-list { |
| 9 | list-style: none; |
| 10 | padding-left: 20px; |
| 11 | } |
| 12 | .nested-item { |
| 13 | padding: 8px; |
| 14 | margin: 5px; |
| 15 | background: #fff; |
| 16 | border: 1px solid #ddd; |
| 17 | cursor: grab; |
| 18 | } |
| 19 | .nested-item:hover { |
| 20 | background: #f0f0f0; |
| 21 | } |
| 22 | </style> |
| 23 | </head> |
| 24 | <body> |
| 25 | |
| 26 | <h2>可拖曳巢狀清單</h2> |
| 27 | |
| 28 | <ul id="nested-list" class="nested-list"> |
| 29 | <li class="nested-item">項目 1 |
| 30 | <ul class="nested-list"> |
| 31 | <li class="nested-item">子項目 1.1</li> |
| 32 | <li class="nested-item">子項目 1.2</li> |
| 33 | </ul> |
| 34 | </li> |
| 35 | <li class="nested-item">項目 2</li> |
| 36 | <li class="nested-item">項目 3 |
| 37 | <ul class="nested-list"> |
| 38 | <li class="nested-item">子項目 3.1</li> |
| 39 | </ul> |
| 40 | </li> |
| 41 | </ul> |
| 42 | |
| 43 | <script src="https://cdn.jsdelivr.net/npm/sortablejs@1.15.0/Sortable.min.js"></script> |
| 44 | <script> |
| 45 | new Sortable(document.getElementById('nested-list'), { |
| 46 | animation: 150, |
| 47 | group: 'nested', |
| 48 | fallbackOnBody: true, |
| 49 | swapThreshold: 0.65 |
| 50 | }); |
| 51 | |
| 52 | document.querySelectorAll('.nested-list').forEach(list => { |
| 53 | new Sortable(list, { |
| 54 | animation: 150, |
| 55 | group: 'nested', |
| 56 | fallbackOnBody: true, |
| 57 | swapThreshold: 0.65 |
| 58 | }); |
| 59 | }); |
| 60 | </script> |
| 61 | |
| 62 | </body> |
| 63 | </html> |
| 64 |