Jquery UI可排序占位符未显示在阻止列表中

时间:2011-07-31 03:24:43

标签: javascript jquery jquery-ui jquery-ui-sortable

我将ul中的一些项目显示为内联块。我能用jquery ui排序它们,但是占位符没有出现。

$(document).ready(function() {
  $('#sortableList').sortable({
    refreshPositions: true,
    opacity: 0.6,
    scroll: true,
    containment: 'parent',
    placeholder: 'placeholder',
    tolerance: 'pointer'
  }).disableSelection();
});
.sequencer {
   height: 110px;
   width: 600px;
   overflow-y: hidden;
   overflow-x: hidden;
 }
 .sequencer ul {
   white-space: nowrap;
   overflow-x: scroll;
   overflow-y: hidden;
 }
 .sequencer li {
   display: inline-block;
   padding-right: 10px;
   padding-left: 10px;
   text-align: center;
 }
 .sequencer img {
   display: block;
   height: 50px;
 }
 .placeholder {
   background: #f3f3f3;
   visibility: visible;
 }
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.7.2/jquery.min.js"></script>
<script src="http://ajax.googleapis.com/ajax/libs/jqueryui/1.8.12/jquery-ui.js"></script>
<div class='sequencer'>
  <ul id='sortableList'>
    <li>
      <img src='http://images.wikia.com/reddithistory/images/1/10/3-rage-face.png' />rage1</li>
    <li>
      <img src='http://images.wikia.com/reddithistory/images/1/10/3-rage-face.png' />rage2</li>
    <li>
      <img src='http://images.wikia.com/reddithistory/images/1/10/3-rage-face.png' />rage3</li>
    <li>
      <img src='http://images.wikia.com/reddithistory/images/1/10/3-rage-face.png' />rage4</li>
    <li>
      <img src='http://images.wikia.com/reddithistory/images/1/10/3-rage-face.png' />rage5</li>
  </ul>
</div>

3 个答案:

答案 0 :(得分:8)

由于您要拖动的项目没有明确的高度,您应该使用选项

  

forcePlaceholderSize

     

如果为true,则强制占位符具有大小。

无需手动指定占位符的维度。

&#13;
&#13;
$(document).ready(function() {
  $('#sortableList').sortable({
    refreshPositions: true,
    opacity: 0.6,
    scroll: true,
    containment: 'parent',
    placeholder: 'placeholder',
    tolerance: 'pointer',
    forcePlaceholderSize: true // <--- add this
  }).disableSelection();
});
&#13;
.sequencer {
  height: 110px;
  width: 600px;
  overflow-y: hidden;
  overflow-x: hidden;
}
.sequencer ul {
  white-space: nowrap;
  overflow-x: scroll;
  overflow-y: hidden;
}
.sequencer li {
  display: inline-block;
  padding-right: 10px;
  padding-left: 10px;
  text-align: center;
}
.sequencer img {
  display: block;
  height: 50px;
}
.placeholder {
  background: #f3f3f3;
  visibility: visible;
}
&#13;
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.7.2/jquery.min.js"></script>
<script src="http://ajax.googleapis.com/ajax/libs/jqueryui/1.8.12/jquery-ui.js"></script>
<div class='sequencer'>
  <ul id='sortableList'>
    <li>
      <img src='http://images.wikia.com/reddithistory/images/1/10/3-rage-face.png' />rage1</li>
    <li>
      <img src='http://images.wikia.com/reddithistory/images/1/10/3-rage-face.png' />rage2</li>
    <li>
      <img src='http://images.wikia.com/reddithistory/images/1/10/3-rage-face.png' />rage3</li>
    <li>
      <img src='http://images.wikia.com/reddithistory/images/1/10/3-rage-face.png' />rage4</li>
    <li>
      <img src='http://images.wikia.com/reddithistory/images/1/10/3-rage-face.png' />rage5</li>
  </ul>
</div>
&#13;
&#13;
&#13;

JSFiddle

答案 1 :(得分:3)

如果您为其设置heightwidth,则可以看到您的占位符。

使用您的代码检查jsfiddle:jsfiddle

答案 2 :(得分:0)

为占位符添加高度宽度和不透明度,然后它将正常工作