欢迎来到尧图网

客户服务 关于我们

您的位置:首页 > 文旅 > 美景 > Sortable.js板块拖拽示例

Sortable.js板块拖拽示例

2025/11/8 6:46:13 来源:https://blog.csdn.net/w11111xxxl/article/details/140415400  浏览:    关键词:Sortable.js板块拖拽示例

图例 代码在图片后面 点赞❤️+关注🙏+收藏⭐️

页面加载后显示

4c7a17789c0b410ab5f519973c2e76d2.jpg

 

 拖拽效果

69144f3e52fb4d668e8d4bc2e1505e62.jpg

 源代码  由于js库使用外链,所以会加载一会儿

<!DOCTYPE html>

<html lang="en">

<head>

    <meta charset="UTF-8">

    <meta name="viewport" content="width=device-width, initial-scale=1.0">

    <title>Sortable.js Example</title>

    <style>

        .list-group {

            display: flex;

            flex-direction: column;

            gap: 1em;

        }

 

        .list-group-item {

            background-color: #fff;

            border: 2px solid #ff0000;

            border-radius: 8px;

            box-shadow: 0 2px 4px rgba(0, 0, 0, 0.1);

            padding: 0.5em;

            width: 150px; /* 减少宽度 */

            height: 70px; /* 设置高度 */

            display: flex;

            align-items: center;

            justify-content: center;

            text-align: center;

        }

 

        .list-group-item.dragging {

            opacity: 0.5;

        }

    </style>

    <!-- 引入 Sortable.js 的 CSS 和 JS 文件 -->

    <link rel="stylesheet" href="https://unpkg.com/sortablejs/Sortable.min.css">

</head>

<body>

    <div id="example-sortable" class="list-group">

        <div class="list-group-item">

            项目 1

        </div>

        <div class="list-group-item">

            项目 2

        </div>

        <div class="list-group-item">

            项目 3

        </div>

        <div class="list-group-item">

            项目 4

        </div>

    </div>

 

    <!-- 引入 Sortable.js 的 JS 文件 -->

    <script src="https://unpkg.com/sortablejs/Sortable.min.js"></script>

    <script>

        // 初始化 Sortable

        var el = document.getElementById('example-sortable');

        Sortable.create(el, {

            group: 'shared', // 允许与其它具有相同组名的元素交互

            animation: 150, // 动画速度

            ghostClass: 'blue-background-class' // 拖动时元素的样式类

        });

    </script>

</body>

</html>

版权声明:

本网仅为发布的内容提供存储空间,不对发表、转载的内容提供任何形式的保证。凡本网注明“来源:XXX网络”的作品,均转载自其它媒体,著作权归作者所有,商业转载请联系作者获得授权,非商业转载请注明出处。

我们尊重并感谢每一位作者,均已注明文章来源和作者。如因作品内容、版权或其它问题,请及时与我们联系,联系邮箱:809451989@qq.com,投稿邮箱:809451989@qq.com

热搜词