简体   繁体   English

如何在jQuery中更改放置区

[英]How to change the drop zone in jQuery

So, I have two problems: 因此,我有两个问题:

  1. Why is this });//]]> at the top of the page in jsfiddle. 为什么是});//]]>在jsfiddle页面顶部。

  2. Second, the real issue, How can I change the drop zone of the jQuery sortable object to reflect where the mouse is. 其次,真正的问题是,如何更改jQuery可排序对象的放置区域以反映鼠标的位置。 So what I mean is, It should not matter where you drag the sortable from (extreme top left corner or bottom right) but instead only rely on if the mouse is over tab1 or tab2 to be dropped. 因此,我的意思是,从何处拖动排序对象(最左上角或右下角)都没有关系,而仅取决于鼠标是否位于要放置的tab1tab2上。

Currently, the center of the sortable has to be over tab1 or tab2 . 当前,sortable的中心必须在tab1tab2

var $tab_items = $("ul:first li", $tabs).droppable({
    accept: ".connectedSortable li",
    hoverClass: "ui-state-hover",
    drop: function (event, ui) {
        var $item = $(this);
        var $list = $($item.find("a").attr("href"))
            .find(".connectedSortable");

        ui.draggable.hide("slow", function () {
            $tabs.tabs("select", $tab_items.index($item));
            $(this).appendTo($list).show("slow");
        });
    }
});

I am fairly new to JavaScript and jQuery. 我对JavaScript和jQuery相当陌生。 I think that drop: function( event, ui ) { is definitely where i should be looking. 我认为drop: function( event, ui ) {绝对是我应该去的地方。 Any insight into this would be greatly appreciated. 任何对此的见解将不胜感激。

http://jsfiddle.net/justinmvail/LARnD/ http://jsfiddle.net/justinmvail/LARnD/

$('selector').droppable({ tolerance: "pointer", ...

See this fiddle 看到这个小提琴

You'll want to set the tolerance option for draggable . 您需要为draggable设置tolerance选项。

The script tags in the fiddle caused the strange characters. 小提琴中的脚本标签引起了奇怪的字符。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM