Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
343 views
in Technique[技术] by (71.8m points)

jQuery sortable nested div issue - not getting placeholder to drop

I need to able to move the outer div below or above the inner div. It can be inside the inner div as well, placeholder is not getting displayed.

If there is already a div available below or above inner div, then it is displaying placeholder.

Here is my code:

$(function() {
  var cancelDrag = false;
  $(".section").sortable({
    connectWith: ".section, .inn_column",
    items: '.row',
    receive: function(event, ui) {
      console.log($(ui.item));
      if ($(ui.item).hasClass("inn_portlet")) {
        $(ui.sender).sortable("cancel");
        cancelDrag = true;
        $(this).sortable('cancel');
        return false;
      } else {
        cancelDrag = false;
        //$(ui.item).find('input:radio')[1].checked = true;
      }
    },
    start: function(event, ui) {
      console.log('start');
    },
    stop: function(event, ui) {
      console.log(cancelDrag);
      console.log('stop');
    },
    update: function(event, ui) {
      var newIndex = ui.item.parent().attr('class');
      var oldIndex = $(this).parent().attr('class');
      console.log(cancelDrag);
      console.log(newIndex);
      console.log('update');
    },
    sort: function(event, ui) {
      console.log('sort');
    },
    change: function(event, ui) {
      console.log('change');
    },
    out: function(event, ui) {
      console.log('out');
    },
    over: function(event, ui) {
      console.log('over');
    },
    //handle: ".row-header",
    //cancel: ".inn_portlet",
    placeholder: "row-placeholder ui-corner-all"
  });
  $(".inn_column").sortable({
    connectWith: ".inn_column, .section",
    //items: '.row, .inn_portlet',
    //handle: ".row-header",
    //cancel: ".row-toggle",
    placeholder: "row-placeholder ui-corner-all",
    start: function(event, ui) {
      console.log('el start');
    },
    stop: function(event, ui) {
      console.log(ui);
      console.log(event);
      console.log('el stop');
    },
    update: function(event, ui) {
      console.log('el update');
    },
    sort: function(event, ui) {
      console.log('el sort');
    },
    change: function(event, ui) {
      console.log('el change');
    },
    out: function(event, ui) {
      console.log('el out');
    },
    over: function(event, ui) {
      console.log('el over');
    },
  });
});
body {
  min-width: 520px;
}

.section {
  width: 170px;
  float: left;
  padding-bottom: 100px;
  border: 1px solid;
  margin: 5px;
}

.inn_portlet,
.row {
  margin: 0 1em 1em 0;
  padding: 0.3em;
}

.row-header {
  padding: 0.2em 0.3em;
  margin-bottom: 0.5em;
  position: relative;
  background: #f0f0f0f0;
}

.row-toggle {
  position: absolute;
  top: 50%;
  right: 0;
  margin-top: -8px;
}

.row-content {
  padding: 0.4em;
}

.row-placeholder {
  border: 1px dotted black;
  margin: 0 1em 1em 0;
  height: 50px;
}

.inn_column {
  border: 1px solid;
  margin: 5px;
}

.inn_column .inn_portlet .row-header {
  background: #fff0f0f0;
}
<!doctype html>
<html lang="en">

<head>
  <meta charset="utf-8">
  <meta name="viewport" content="width=device-width, initial-scale=1">
  <link rel="stylesheet" href="//code.jquery.com/ui/1.12.1/themes/base/jquery-ui.css">
  <script src="https://code.jquery.com/jquery-1.10.2.js"></script>
  <script src="https://code.jquery.com/ui/1.10.4/jquery-ui.js"></script>
</head>

<body>

  <div class="section" id="s1">

    <div class="inn_column">

      <div class="row">
        <div class="row-header">Outer</div>
      </div>

      <div class="row">
        <div class="row-header">Outer</div>
      </div>

      <div class="inn_portlet">
        <div class="row-header">Inner</div>
      </div>

      <div class="inn_portlet">
        <div class="row-header">Inner</div>
      </div>

      <div class="row">
        <div class="row-header">Outer</div>
      </div>

    </div>

  </div>

  <div class="section">

    <div class="row">
      <div class="row-header">Outer</div>
    </div>
    <div class="inn_column">

      <div class="inn_portlet">
        <div class="row-header">Inner</div>
      </div>

      <div class="inn_portlet">
        <div class="row-header">Inner</div>
      </div>

    </div>
  </div>

  <div class="section">

    <div class="row">
      <div class="row-header">Outer</div>
    </div>

    <div class="row">
      <div class="row-header">Outer</div>
    </div>

    <div class="inn_column">

      <div class="inn_portlet">
        <div class="row-header">Inner</div>
      </div>

      <div class="inn_portlet">
        <div class="row-header">Inner</div>
      </div>

    </div>

  </div>


</body>

</html>

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)
等待大神答复

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...