【问题标题】:How to reimplement jQuery's default helper in a custom helper如何在自定义帮助器中重新实现 jQuery 的默认帮助器
【发布时间】:2010-09-16 05:26:38
【问题描述】:

我正在创建一个自定义拖动助手(在 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;
    }
}

但我根本无法使用原始功能。 return clone() 工作正常,但 return $(this) 没有任何乐趣。

【问题讨论】:

    标签: javascript jquery


    【解决方案1】:

    好的,当我输入这个问题时,我做了更多的来源潜水,发现了这条小线:

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

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

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2011-09-06
      • 1970-01-01
      • 2014-12-02
      • 1970-01-01
      • 1970-01-01
      • 2011-04-29
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多