【问题标题】:How to drag the element to outside when mCustomScrollbar is enabled启用 mCustomScrollbar 时如何将元素拖到外部
【发布时间】:2016-03-31 13:18:10
【问题描述】:

我将元素从一个 div 拖到另一个 div 上,而拖动元素不可见

我使用 jquery mCustomScrollbar 插件来滚动

http://jsfiddle.net/jt1c8o81/

HTML 代码

<table><tr>
    <td><div id="ParentDiv" class="mCustomScrollbar _mCS_4 ui-sortable ui-droppable"></div></td>
<td><div style="border:1px solid blue;float:left;margin-top:0px;" class="drop">DROP HERE
    </div></td></tr>
    </table>

JQuery 代码

for (var i = 0; i < 100; i++) {
    var el = "<div class='childDiv draggable'>iData " + i + "</div>";
    $("#ParentDiv").append(el);
}

$(".draggable").draggable({
    containment: "window",
    cursor: "crosshair",
    revert: "invalid",
    scroll: true,
    stop: function (event, ui) {
        if ($(this).hasClass("tsh")) {
            $(this).attr("style", "");

        }
    },
    drag: function (event, ui) {
        var offset = $(this).offset();
        var xPos = offset.left;
        var yPos = offset.top;
      //  $(this).text('x: ' + xPos + 'y: ' + yPos);
        var shw_xy = 'x: ' + xPos + 'y: ' + yPos;
        console.log(shw_xy);


    }

});
$(".drop").droppable({
    accept: ".draggable",
    activeClass: "myhighlight",
    drop: function (event, ui) {
 $(this).removeClass("border").removeClass("over");
                    //$(this).addClass("over");
                    var dropped = ui.draggable;
                    var droppedOn = $(this);


                    $(dropped).detach().css({
                        top: 0,
                        left: 0
                    }).appendTo(droppedOn);
    },
    over: function (event, elem) {
        $(this).addClass("over");
        $(this).removeClass("img_added");

        var $this = $(this);

        console.log("over");

    },
    activate: function (event, elem) {

    }
});

CSS

#ParentDiv {
    background-color: #ffffff;
    border: 1px solid #e1d193;
    border-radius: 4px;
    float: left;
    height: 600px;
    margin-bottom: 10px;
    margin-left: 15px;
    min-height: 200px;

    padding-bottom: 20px;
    padding-left: 23px;
    padding-top: 20px;
    width: 252px;
}
#ParentDiv .childDiv {
    border:1px solid red;
    border-radius: 4px;
    height: auto;
    margin: 2px;
    position: relative;
    z-index: 5000;
}
#ParentDiv .childDiv {
    float: left;
    height: auto;
    width: 70px;
}
.childDiv {
    border:1px solid green;
    border-radius: 4px;
    height: auto;
    margin: 2px;
    position: relative;
    z-index: 5000;
}
 .childDiv {
    float: left;
    height: auto;
    width: 70px;
    margin:2px;
}

谁能告诉我我哪里错了

【问题讨论】:

    标签: javascript jquery jquery-ui jquery-plugins mcustomscrollbar


    【解决方案1】:

    请使用 helper:"clone" 和 appendTo 函数。检查下面的代码。

    $(".element").draggable({
        helper: function () { return $
            (this).clone().appendTo(".element").css("zIndex",2).show();
        }
    });
    

    【讨论】:

      【解决方案2】:

      我提到带有拖动元素的容器隐藏了溢出。这就是为什么您在拖动时看不到元素的原因。只需将溢出设置为在拖动开始时可见并在拖动结束时返回隐藏:

         stop: function (event, ui) {
             $(".mCustomScrollBox").attr("style", "overflow: hidden !important;");
        $(".mCSB_container").attr("style", "overflow: hidden !important;");
      },
      start: function(event,ui){
          $(".mCustomScrollBox ").attr("style", "overflow: visible !important;");
           $(".mCSB_container").attr("style", "overflow: visible !important;");
      },
      

      在这里查看它是如何工作的:

      http://jsfiddle.net/jt1c8o81/19/

      【讨论】:

      • 删除后 mCustomScrollbar 不起作用。请检查一次
      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2019-07-17
      • 1970-01-01
      • 2012-10-03
      • 1970-01-01
      • 2013-12-14
      • 1970-01-01
      相关资源
      最近更新 更多