【问题标题】:jquery-ui draggable inside a tab cannot be dragged outside container with overflow-y可在选项卡内拖动的 jquery-ui 不能用溢出-y 拖动到容器外
【发布时间】:2014-03-28 06:48:00
【问题描述】:

我在选项卡窗格内有一个可拖动的,它位于设置为溢出-y 的容器内:滚动。但是draggable不能被拖到容器外(这是必需的,因为放置目标在容器外!)。

HTML

<div class="container">
    <div id="tabs">
      <ul>
        <li><a href="#tabs-1">Header</a></li>
      </ul>
      <div id="tabs-1">
        <div class="drag">
        </div>
        <p>Drag the pink box. It cannot go outside the gray container. If "overflow-y: scroll" is removed from its css, the box can be dragged outside.</p>
      </div>
    </div>
    <p>
        <div class="drag"></div> If the box is not inside of a tab, it can dragged outside the container.
    </p>
</div>

CSS

.container {
    height: 350px;
    overflow-y: scroll;
    background-color: #fafafa;
    width: 75%;
}

.drag {
    width: 20px;
    height: 20px;
    background-color: lightpink;
}

Javascript

$("#tabs").tabs();
$(".drag").draggable({helper: "clone"});

在http://jsfiddle.net/79u5a/2/试试这个

在我的应用程序中,我有各种这样的容器(具有溢出-y)并且每个容器都包含可拖动对象。除选项卡内的那些之外,所有可拖动对象都有效。 请告诉我一个解决方案。我需要能够将选项卡中的框拖到容器外。

【问题讨论】:

    标签: jquery jquery-ui


    【解决方案1】:

    在我看来,您的问题是您在问题中提到的overflow-y,所以我有一个解决方案,如果您可以创建另一个像.containerA{...} 这样的类但没有overflow css 属性,那么您可以这样做:

    CSS:

    .containerA {
      height: 350px;
      background-color: #fafafa;
      width: 75%;
      /* this class without overflow property*/
    }
    

    jQuery:

    $(".drag").draggable({
       helper: "clone",
       start: function (e, ui) {
          $('.container').toggleClass('container containerA');
       },
       stop: function (e, ui) {
          $('.containerA').toggleClass('containerA container');
       }
    });
    

    Fiddle

    【讨论】:

    • 嗯.. 很有趣,虽然改变样式会导致页面布局发生变化,这可能看起来不正确。另外,我想知道/为什么/选项卡外面的框可以工作,而里面的那个不行?
    • Ummm...这可能是由于 js 因为你实现了它的标签功能所以我认为有一些东西不会让它移出。
    • 找到答案了!在查看可拖动 api 时,有一个名为“appendTo”的选项,它允许您说出助手附加到哪个元素。将appendTo: ".container" 添加到可拖动选项中,效果非常棒!
    猜你喜欢
    • 2011-08-16
    • 2012-10-29
    • 2012-09-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2011-01-07
    • 2018-04-14
    • 1970-01-01
    相关资源
    最近更新 更多