jquery-ui - Bootstrap 3列类干扰jquery-ui droppable div

标签 jquery-ui twitter-bootstrap-3

我使用 jQuery-UI v1.11.2 来创建一些可拖动和可放置的 div,以及 Boostrap 3.1.1。

我想知道为什么 Boostrap 列类会干扰可拖动的“提示”。

换句话说,当我将图像从 Gallery div 拖到 Dashboard div 时,Dashboard div 出现在图像提示的前面。然后,一旦我将图像拖放到仪表板 div 上,该图像就会重新出现。

如果我从仪表板 div 中删除 col-md-8 类,这个问题就会消失。

这里有两个屏幕截图来演示:

1) 右侧 div 上没有 Bootstrap 列类(图像提示看起来不错)

2)将 Bootstrap 列类放在右侧 div 上(图像提示消失)

Good draggable hint without the Bootstrap column class

Bad draggable hint with the Bootstrap column class

这是 HTML 代码:

<section id="gadgets-view" class="mainbar" data-ng-controller="gadgets">

<div class="container-fluid">                       
    <div class="row-fluid">
        <!-- based on http://jqueryui.com/droppable/#photo-manager -->
        <div class="ui-widget ui-helper-clearfix  col-md-4">    <-- GALLERY OF WIDGETS -->
            <ul id="gallery" class="gallery ui-helper-reset ui-helper-clearfix">
                <li class="ui-widget-content ui-corner-tr">
                    <h5 class="ui-widget-header">Tree Grid</h5>                    
                    <img src="images/treegrid.jpg" alt="Hierarchy Grid" width="96" height="72">
                </li>
                <li class="ui-widget-content ui-corner-tr">
                    <h5 class="ui-widget-header">Area Chart</h5>
                    <img src="images/chart_area.jpg" alt="Area Chart" width="96" height="72">

                </li>
                <li class="ui-widget-content ui-corner-tr">
                    <h5 class="ui-widget-header">Bar Chart</h5>
                    <img src="images/chart_bar.png" alt="Bar Chart" width="96" height="72">                    
                </li>
                <li class="ui-widget-content ui-corner-tr">
                    <h5 class="ui-widget-header">Column Chart</h5>
                    <img src="images/chart_column.png" alt="Column  Chart" width="96" height="72">                        
                    <a href="link/to/dashboard/script/when/we/have/js/off" title="Add this gadget" class="ui-icon ui-icon-plus"></a>
                </li>
                <li class="ui-widget-content ui-corner-tr">
                    <h5 class="ui-widget-header">Line Chart</h5>
                    <img src="images/chart_line.png" alt="Line  Chart" width="96" height="72">

                </li>
            </ul>                
        </div>
        <div class="col-md-8">
            <div id="dashboard" class="ui-widget-content ui-state-default  ">   <-- DROPPABLE DASHBOARD -->
                <h4 class=""><span class="ui-icon ui-icon-image"></span>Dashboard</h4>
            </div>
        <div>
    </div>
</div>
</section>

CSS:

<style>    
.ui-widget-header{
    font-size: 65%;
    font-family: "Trebuchet MS", "Helvetica", "Arial", "Verdana", "sans-serif";      
}
.ui-state-highlight {
    border: 2px dashed #d3d3d3;  /* override to show dashed border when dragging */
}
#gallery {
    float: left;
    width: 75%;
    min-height: 12em;
}

.gallery.custom-state-active {
    background: #eee;
}

.gallery li {
    list-style: none;
    float: left;
    width: 96px;
    padding: 0.4em;
    margin: 0 0.4em 0.4em 0;
    text-align: center;
}

    .gallery li h5 {
        margin: 0 0 0.4em;
        cursor: move;
    }

    .gallery li a {
        float: right;
    }

        .gallery li a.ui-icon-zoomin {
            float: left;
        }

    .gallery li img {
        width: 100%;
        cursor: move;
    }

#dashboard {
    float: left;
    width: 45%;
    height:500px;
    padding: 1%;
}

    #dashboard h4 {
        line-height: 25px;
        margin: 0 0 0.4em;
    }

        #dashboard h4 .ui-icon {
            float: left;
        }

    #dashboard .gallery h5 {
        display: none;
    }

用于创建拖放区域的 JavaScript :

<script>
$(function () {
    // there's the gallery and the dashboard
    var $gallery = $("#gallery"),
      $dashboard = $("#dashboard");

    // let the gallery items be draggable
    $("li", $gallery).draggable({
        cancel: "a.ui-icon", // clicking an icon won't initiate dragging
        revert: "invalid", // when not dropped, the item will revert back to its initial position
        containment: "document",
        helper: "clone",
        cursor: "move"
    });

    // let the dashboard be droppable, accepting the gallery items
    $dashboard.droppable({
        accept: "#gallery > li",
        activeClass: "ui-state-highlight",
        drop: function (event, ui) {
            debugger;
            deleteImage(ui.draggable);
        }
    });

    // let the gallery be droppable as well, accepting items from the dashboard
    $gallery.droppable({
        accept: "#dashboard li",
        activeClass: "custom-state-active",
        drop: function (event, ui) {
            recycleImage(ui.draggable);
        }
    });

    // image deletion function
    var recycle_icon = "<a href='link/to/recycle/script/when/we/have/js/off' title='Remove gadget' class='ui-icon ui-icon-minus'></a>";
    function deleteImage($item) {
        $item.fadeOut(function () {
            var $list = $("ul", $dashboard).length ?
              $("ul", $dashboard) :
              $("<ul class='gallery ui-helper-reset'/>").appendTo($dashboard);

            //$item.find("a.ui-icon-dashboard").remove();   // DO NOT REMOVE ORIGINAL WIDGET ICON - 11/19/2014 BM:
            $item.append(recycle_icon).appendTo($list).fadeIn(function () {
                //$item.animate({ width: "48px" }).find("img").animate({ height: "36px" });
                $item.animate().find("img").animate();
            });
        });
    }

    // image recycle function
    var dashboard_icon = "<a href='link/to/dashboard/script/when/we/have/js/off' title='Add this gadget' class='ui-icon ui-icon-plus'</a>";
    function recycleImage($item) {
        $item.fadeOut(function () {
            $item
              .find("a.ui-icon-refresh")
                .remove()
              .end()
              .css("width", "96px")
              .append(dashboard_icon)
              .find("img")
                .css("height", "72px")
              .end()
              .appendTo($gallery)
              .fadeIn();
        });
    }

    // image preview function, demonstrating the ui.dialog used as a modal window
    function viewLargerImage($link) {
        var src = $link.attr("href"),
          title = $link.siblings("img").attr("alt"),
          $modal = $("img[src$='" + src + "']");

        if ($modal.length) {
            $modal.dialog("open");
        } else {
            var img = $("<img alt='" + title + "' width='384' height='288' style='display: none; padding: 8px;' />")
              .attr("src", src).appendTo("body");
            setTimeout(function () {
                img.dialog({
                    title: title,
                    width: 400,
                    modal: true
                });
            }, 1);
        }
    }

    // resolve the icons behavior with event delegation
    $("ul.gallery > li").click(function (event) {
        var $item = $(this),
          $target = $(event.target);

        if ($target.is("a.ui-icon-dashboard")) {
            deleteImage($item);
        } else if ($target.is("a.ui-icon-zoomin")) {
            viewLargerImage($target);
        } else if ($target.is("a.ui-icon-refresh")) {
            recycleImage($item);
        }

        return false;
    });
});

最佳答案

我发现了您描述的问题(但我没有发现与 Bootstrap 网格类的关系)。

对于我来说,问题似乎与 z-index 有关,可以通过在 CSS 代码末尾添加以下样式规则来解决:

.ui-draggable-handle {
z-index: 1;
}   

关于jquery-ui - Bootstrap 3列类干扰jquery-ui droppable div,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27042564/

相关文章:

c# - 无法从 "jQuery Tag-it!"获取标记

css - Jquery 和 css 引用在 IE7 兼容性上阻止 Asp.net 中的页面呈现

css - 在页脚中显示菜单,但在移动设备上显示在页眉中

css - float Bootstrap 下拉列表内容上方和侧边栏主菜单的右侧

javascript - 在 Bootstrap 3.0 中设置/取消设置复选框按钮的代码

html - Bootstrap 3 - 在同一行显示文本和图像

javascript - Internet Explorer 7 8 : jQuery UI effects work only once

jquery - 如何在 iframe 外部的父窗口上显示 Jquery UI 对话框

jquery - jtable "Add new record"css 不显示

css - 使用 Bootstrap3 在容器中分发元素