Last active 9 months ago

本範例使用 SortableJS 實現 Grid 佈局的可拖放排序,允許用戶調整區塊順序,適用於 視覺化管理、儀表板排序、圖片排列與動態 UI 佈局 等應用。

timmy revised this gist 9 months ago. Go to revision

1 file changed, 50 insertions

sortablejs_grid_layout.html(file created)

@@ -0,0 +1,50 @@
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>
Newer Older