2008-10-09 9 views
2

我创建一个自定义的拖帮手(jQuery中):如何重新实现jQuery的缺省助手在自定义帮助

$('.dragme', element).draggable({ 
    appendTo: 'body', 
    helper : custom_drag_helper, 
    opacity : 0.5 
}); 

我这样做是因为我想有时克隆,有时做的默认功能,即拖动原始元素。

function custom_drag_helper() { 
    if (/*criteria on when to move instead of clone */) { 
     return $(this); /* this is what helper: 'original' seems to do */ 
    } else { 
     clone = $(this).clone(); /* this is what helper: 'clone' does */ 
     return clone; 
    } 
} 

但是我无法获得原始的功能。返回克隆()工作正常,但返回$(这)没有喜悦。

回答

5

好,打字这个问题我确实有点多源潜水,发现这个小行当:

if (this.options.helper == 'original' && !(/^(?:r|a|f)/).test(this.element.css("position"))) 
     this.element[0].style.position = 'relative'; 

我没有在我花了试图解决这个问题一天发现。将this.style.position = 'relative';添加到我的代码上面解决了问题!