jQueryUI Sortable 应用Demo

最近工作用需要设计一个自由布局的页面设计。我选了jQuery UI 的 sortable ,可以拖拽,自由排序 使用很方便,写一个demo,做个记录。

第一、单项目自由排序

下图效果

代码段:

<script type="text/javascript">  

    $(function () {
        $("#box_wrap").sortable({
            helper: "clone",
            placeholder: "box-holdplace",
            sort: function (e, ui) {
               //排序时触发事件
            },
           // handle: ".handle",//指定元素内的某种元素才可以拖动,非常有用
        }).disableSelection();      
    });
</script>

 html:

<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8" />
    <title></title>
    <link href="js/bootstrap/css/bootstrap.css" rel="stylesheet" />
    <link href="js/bootstrap/css/bootstrap-theme.min.css" rel="stylesheet" />
    <link href="css/index.css" rel="stylesheet" />

    <script src="js/jquery-1.10.2.min.js"></script>
    <script src="js/bootstrap/js/bootstrap.min.js"></script>

    <!--Sortable -->
    <script src="//apps.bdimg.com/libs/jqueryui/1.10.4/jquery-ui.min.js"></script>
</head>
<body>
    <div class="box_wrap" id="box_wrap">
        <div class="box">
            test1
        </div>
        <div class="box">
            test2
        </div>
        <div class="box">test3
        </div>
    </div>
</body>
</html>

  

第二、多排序组之间自由拖拽

 

代码段:

<script type="text/javascript">
       
    $(function () {
        $("#box_wrap1,#box_wrap2").sortable({
            connectWith: ".box_wrap",
            helper: "clone",
            cursor: "move",//移动时候鼠标样式         
            opacity: 0.5, //拖拽过程中透明度
            placeholder: "box-holdplace",//占位符className,设置一个样式         
        }).disableSelection();
    });
</script>

  html 代码:

<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8" />
    <title></title>
    <link href="js/bootstrap/css/bootstrap.css" rel="stylesheet" />
    <link href="js/bootstrap/css/bootstrap-theme.min.css" rel="stylesheet" />
    <link href="css/index.css" rel="stylesheet" />

    <script src="js/jquery-1.10.2.min.js"></script>
    <script src="js/bootstrap/js/bootstrap.min.js"></script>

    <!--Sortable -->
    <script src="//apps.bdimg.com/libs/jqueryui/1.10.4/jquery-ui.min.js"></script>

</head>
<body>
    <div class="container">
        <div class="row">
            <div class="column col-md-6">
                <div class="box_wrap" id="box_wrap1">
                    <div class="box">
                        left-test1
                    </div>
                    <div class="box">
                        left-test2
                    </div>
                    <div class="box">
                        left-test3
                    </div>
                </div>
            </div>
            <div class="column col-md-6">
                <div class="box_wrap" id="box_wrap2" >
                    <div class="box">
                        test1
                    </div>
                    <div class="box">
                        test2
                    </div>
                    <div class="box">
                        test3
                    </div>
                </div>
            </div>
        </div>     
    </div>
</body>
</html>
View Code

上面另种是工作中比较常用的排序形式。具体API参数可以参考

http://www.css88.com/jquery-ui-api/sortable/#event-out

 

转载于:https://www.cnblogs.com/clc2008/p/7487156.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
最新官方jQuery UI插件 主流特效Demo,绝不含糊。 好东西不需要过多的言辞修饰,下了就知道! 所有效果说明: 基本的鼠标互动: 拖拽(drag and dropping)、排序(sorting)、选择(selecting)、缩放(resizing) 各种互动效果: 手风琴式的折叠菜单(accordions)、日历(date pickers)、对话框(dialogs)、滑动条 (sliders)、表格排序(table sorters)、页签(tabs) 放大镜效果(magnifier)、阴影效果(shadow) 第一部分:鼠标交互 1.1 Draggables:拖拽 所需文件: ui.mouse.js ui.draggable.js ui.draggable.ext.js 用法:文件载入后,可以拖拽class = "block"的层 $(document).ready(function(){ $(".block").draggable(); }); draggable(options)可以跟很多选项 选项说明:http://docs.jquery.com/UI/Draggables/draggable#options 选项实例:http://dev.jquery.com/view/trunk/plugins/ui/tests/draggable.html 1.2 Droppables 所需要文件,drag drop ui.mouse.js ui.draggable.js ui.draggable.ext.js ui.droppable.js ui.droppable.ext.js 用法: $(document).ready(function(){ $(".block").draggable({helper: 'clone'}); $(".drop").droppable({ accept: ".block", activeClass: 'droppable-active', hoverClass: 'droppable-hover', drop: function(ev, ui) { $(this).append("Dropped!"); } }); }); 选项说明:http://docs.jquery.com/UI/Droppables/droppable#options 选项实例:http://dev.jquery.com/view/trunk/plugins/ui/tests/droppable.html 1.3 Sortables 排序 所需要的文件 jquery.dimensions.js ui.mouse.js ui.draggable.js ui.droppable.js ui.sortable.js 用法: $(document).ready(function(){ $("#myList").sortable({}); }); dimensions文档http://jquery.com/plugins/project/dimensions 选项说明:http://docs.jquery.com/UI/Sortables/sortable#options 选项实例:http://dev.jquery.com/view/trunk/plugins/ui/demos/ui.sortable.html 1.4 Selectables 选择 所需要的文件 jquery.dimensions.js ui.mouse.js ui.draggable.js ui.droppable.js ui.selectable.js 用法: $(document).ready(function(){ $("#myList").selectable(); }); 选项说明:http://docs.jquery.com/UI/Selectables/selectable#options 选项实例:http://dev.jquery.com/view/trunk/plugins/ui/tests/selectable.html 1.5 Resizables改变大小 所需要的文件 ,此例子需要几个css文件 jquery.dimensions.js ui.mouse.js ui.resizable.js 用法: $(document).ready(function(){ $("#example").resizable(); }); CSS文件:http://dev.jquery.com/view/trunk/themes/flora/flora.all.css 选项说明:http://docs.jquery.com/UI/Resizables/resizable#options 选项实例:http://dev.jquery.com/view/trunk/plugins/ui/demos/ui.resizable.html 第二部分:互动效果 2.1 Accordion 折叠菜单 所需要的文件: ui.accordion.js jquery.dimensions.js 用法: $(document).ready(function(){ $("#example").accordion(); }); CSS文件:http://dev.jquery.com/view/trunk/themes/flora/flora.all.css 选项说明:http://docs.jquery.com/UI/Accordion/accordion#options 选项实例:http://dev.jquery.com/view/trunk/plugins/accordion/?p=1.1.1 2.2 dialogs 对话框 所需要的文件: jquery.dimensions.js ui.dialog.js ui.resizable.js ui.mouse.js ui.draggable.js 用法: $(document).ready(function(){ $("#example").dialog(); }); CSS文件:http://dev.jquery.com/view/trunk/themes/flora/flora.all.css 选项说明:http://docs.jquery.com/UI/Dialog/dialog#options 选项实例:http://dev.jquery.com/view/trunk/plugins/ui/tests/dialog.html 2.3 sliders 滑动条 所需要的文件 jquery.dimensions.js ui.mouse.js ui.slider.js 用法: $(document).ready(function(){ $("#example").slider(); }); CSS文件:http://dev.jquery.com/view/trunk/themes/flora/flora.all.css 选项说明:http://docs.jquery.com/UI/Slider/slider#options 选项实例:http://dev.jquery.com/view/trunk/plugins/ui/demos/ui.slider.html 2.4 Tablesorter表格排序 所需要的文件 ui.tablesorter.js 用法: $(document).ready(function(){ $("#example").tablesorter({sortList:[[0,0],[2,1]], widgets: ['zebra']}); }); CSS文件:http://dev.jquery.com/view/trunk/themes/flora/flora.all.css 选项说明:http://docs.jquery.com/Plugins/Tablesorter/tablesorter#options 选项实例:http://tablesorter.com/docs/#Demo 2.5 tabs页签(对IE支持不是很好) 所需要的文件 ui.tabs.js 用法: $(document).ready(function(){ $("#example > ul").tabs(); }); CSS文件:http://dev.jquery.com/view/trunk/themes/flora/flora.all.css 选项说明:http://docs.jquery.com/UI/Tabs/tabs#initialoptions 选项实例:http://dev.jquery.com/view/trunk/plugins/ui/tests/tabs.html tabs ext http://stilbuero.de/jquery/tabs_3/rotate.html 第三部分:效果 3.1 Shadow 阴影 实例http://dev.jquery.com/view/trunk/plugins/ui/demos/ui.shadow.html 3.2 Magnifier 放大 实例http://dev.jquery.com/view/trunk/plugins/ui/demos/ui.magnifier.html
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值