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

发布于 2024-11-27 01:38:48 字数 1895 浏览 1 评论 0原文

我在 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>

I have a few items in a ul being displayed as an inline-block. I'm able to sort them with jquery ui's sortable, but the placeholder is not showing up.

$(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>

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

奈何桥上唱咆哮 2024-12-04 01:38:48

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

forcePlaceholderSize

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

无需手动指定占位符的尺寸。

$(document).ready(function() {
  $('#sortableList').sortable({
    refreshPositions: true,
    opacity: 0.6,
    scroll: true,
    containment: 'parent',
    placeholder: 'placeholder',
    tolerance: 'pointer',
    forcePlaceholderSize: true // <--- add this
  }).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>

JSFiddle

Since the items you're dragging doesn't have an explicit height, You should use the option

forcePlaceholderSize.

If true, forces the placeholder to have a size.

No need to manually specify dimensions for placeholder.

$(document).ready(function() {
  $('#sortableList').sortable({
    refreshPositions: true,
    opacity: 0.6,
    scroll: true,
    containment: 'parent',
    placeholder: 'placeholder',
    tolerance: 'pointer',
    forcePlaceholderSize: true // <--- add this
  }).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>

JSFiddle

初熏 2024-12-04 01:38:48

如果您设置了高度宽度,您的占位符将可见。

检查 jsfiddle 与您的代码: jsfiddle

Your placeholder will be visible if you set height and width to it.

Check jsfiddle with your code: jsfiddle

还如梦归 2024-12-04 01:38:48

将高度宽度和不透明度添加到占位符中,然后它就可以正常工作

Add height width and opacity to your placeholder, then it will work fine

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文