如何在自定义帮助器中重新实现jQuery的默认帮助器 [英] How to reimplement jQuery's default helper in a custom helper

查看:42
本文介绍了如何在自定义帮助器中重新实现jQuery的默认帮助器的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在创建一个自定义拖动助手(在jQuery中):

I'm creating a custom drag helper (in jQuery):

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

我这样做是因为我希望有时克隆并且有时会执行默认功能,即拖动原始元素。

I'm doing this because I want to sometimes clone and sometimes do the default functionality, i.e. drag the original element.

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()工作正常,但返回$(this)没有任何乐趣。

But I can't get the original functionality to work at all. return clone() works fine but return $(this) gives no joy.

推荐答案

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

Ok, when typing up this question I did a bit more source diving and discovered this little line:

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

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

which I didn't find in the day I spent trying to solve this problem. Adding this.style.position = 'relative'; to my code above fixed the problem!

这篇关于如何在自定义帮助器中重新实现jQuery的默认帮助器的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆