温馨提示×

温馨提示×

您好,登录后才能下订单哦!

密码登录×
登录注册×
其他方式登录
点击 登录注册 即表示同意《亿速云用户服务条款》

jQueryUI中Sortable怎么用

发布时间:2021-08-18 15:06:36 来源:亿速云 阅读:117 作者:小新 栏目:web开发

这篇文章主要介绍jQueryUI中Sortable怎么用,文中介绍的非常详细,具有一定的参考价值,感兴趣的小伙伴们一定要看完!

下图效果

jQueryUI中Sortable怎么用

代码段:

<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="external nofollow" rel="external nofollow" rel="stylesheet" />
  <link href="js/bootstrap/css/bootstrap-theme.min.css" rel="external nofollow" rel="external nofollow" rel="stylesheet" />
  <link href="css/index.css" rel="external nofollow" rel="external nofollow" 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>

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

jQueryUI中Sortable怎么用

代码段:

<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="external nofollow" rel="external nofollow" rel="stylesheet" />
  <link href="js/bootstrap/css/bootstrap-theme.min.css" rel="external nofollow" rel="external nofollow" rel="stylesheet" />
  <link href="css/index.css" rel="external nofollow" rel="external nofollow" 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>

上面另种是工作中比较常用的排序形式。

以上是“jQueryUI中Sortable怎么用”这篇文章的所有内容,感谢各位的阅读!希望分享的内容对大家有帮助,更多相关知识,欢迎关注亿速云行业资讯频道!

向AI问一下细节

免责声明:本站发布的内容(图片、视频和文字)以原创、转载和分享为主,文章观点不代表本网站立场,如果涉及侵权请联系站长邮箱:is@yisu.com进行举报,并提供相关证据,一经查实,将立刻删除涉嫌侵权内容。

AI