我正在创建一个自定义拖动助手(在jQuery中):
$('.dragme', element).draggable({
appendTo: 'body',
helper : custom_drag_helper,
opacity : 0.5
});
Run Code Online (Sandbox Code Playgroud)
我这样做是因为我想有时克隆并且有时会执行默认功能,即拖动原始元素.
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;
}
}
Run Code Online (Sandbox Code Playgroud)
但我无法使用原始功能.return clone()工作正常,但返回$(this)没有任何乐趣.
好的,在输入这个问题时,我做了一些更多的潜水源并发现了这条小线:
if (this.options.helper == 'original' && !(/^(?:r|a|f)/).test(this.element.css("position")))
this.element[0].style.position = 'relative';
Run Code Online (Sandbox Code Playgroud)
我在尝试解决这个问题的那一天没有找到.添加this.style.position = 'relative';到我上面的代码修复了问题!
| 归档时间: |
|
| 查看次数: |
3469 次 |
| 最近记录: |