sortablejs_grid_layout.html
· 1.1 KiB · HTML
Исходник
<!DOCTYPE html>
<html lang="zh-TW">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>SortableJS Grid 拖曳排序</title>
<style>
.grid-container {
display: flex;
flex-wrap: wrap;
gap: 10px;
width: 320px;
}
.grid-item {
width: 100px;
height: 100px;
background: #3498db;
color: white;
display: flex;
justify-content: center;
align-items: center;
font-size: 18px;
border-radius: 5px;
cursor: grab;
}
</style>
</head>
<body>
<h2>可拖曳的 Grid 佈局</h2>
<div id="grid" class="grid-container">
<div class="grid-item">1</div>
<div class="grid-item">2</div>
<div class="grid-item">3</div>
<div class="grid-item">4</div>
<div class="grid-item">5</div>
<div class="grid-item">6</div>
</div>
<script src="https://cdn.jsdelivr.net/npm/sortablejs@1.15.0/Sortable.min.js"></script>
<script>
new Sortable(document.getElementById('grid'), {
animation: 150,
ghostClass: 'sortable-ghost'
});
</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 Grid 拖曳排序</title> |
| 7 | <style> |
| 8 | .grid-container { |
| 9 | display: flex; |
| 10 | flex-wrap: wrap; |
| 11 | gap: 10px; |
| 12 | width: 320px; |
| 13 | } |
| 14 | .grid-item { |
| 15 | width: 100px; |
| 16 | height: 100px; |
| 17 | background: #3498db; |
| 18 | color: white; |
| 19 | display: flex; |
| 20 | justify-content: center; |
| 21 | align-items: center; |
| 22 | font-size: 18px; |
| 23 | border-radius: 5px; |
| 24 | cursor: grab; |
| 25 | } |
| 26 | </style> |
| 27 | </head> |
| 28 | <body> |
| 29 | |
| 30 | <h2>可拖曳的 Grid 佈局</h2> |
| 31 | |
| 32 | <div id="grid" class="grid-container"> |
| 33 | <div class="grid-item">1</div> |
| 34 | <div class="grid-item">2</div> |
| 35 | <div class="grid-item">3</div> |
| 36 | <div class="grid-item">4</div> |
| 37 | <div class="grid-item">5</div> |
| 38 | <div class="grid-item">6</div> |
| 39 | </div> |
| 40 | |
| 41 | <script src="https://cdn.jsdelivr.net/npm/sortablejs@1.15.0/Sortable.min.js"></script> |
| 42 | <script> |
| 43 | new Sortable(document.getElementById('grid'), { |
| 44 | animation: 150, |
| 45 | ghostClass: 'sortable-ghost' |
| 46 | }); |
| 47 | </script> |
| 48 | |
| 49 | </body> |
| 50 | </html> |
| 51 |