jQuery,Sortabtable:我想拖动中心,但身高错了?

时间:2013-01-21 10:58:15

标签: jquery jquery-ui-sortable

我有以下可拖动的列表项结构:

<ul id="dadCol_0" class="dad-list ui-sortable">
<li class="dad-item ui-draggable" id="sl1" style="position: relative;">1</li>
<li class="dad-item ui-draggable" id="sl2" style="position: relative;">2</li>
<li class="dad-item ui-draggable" id="sl3" style="position: relative;">3</li>
<li class="dad-item ui-draggable" id="sl4" style="position: relative;">4</li>
<li class="dad-item ui-draggable" id="sl5" style="position: relative;">5</li>
</ul>

jQuery:

dad_list.sortable({
    connectWith: 'ul.dad-list',
    containment: '#containment',
    items: 'li.dad-item',
    cursorAt: {
        top: Math.round($(this).outerHeight() / 2)
    },
    stop: function(event, ui) {
        serializedads();
    }       
});

这一切都没问题,但它看起来.outerHeight()为0,被拖动的项目停留在顶部。我需要高度/ 2位置。

1 个答案:

答案 0 :(得分:0)

尝试

cursorAt: function(ui){
    top: Math.round($(ui.item).outerHeight() / 2)
}