本文介绍了jQuery UI可拖动的绝对绝对值而不是相对值?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个div,其中包含几个jquery可拖动对象,但是,如果我随时从页面中删除其中一个可拖动对象,则可以将它们中的其他可拖动对象移动到相对位置.

I have a div containing a few jquery draggables, however if at any point I remove one of these draggables from the page then this can move the rest of them as they are positioned with relative.

这是一个小提琴,展示了这一点: http://jsfiddle.net/VolatileStorm/aNk6e/

Here is a fiddle showcasing this:http://jsfiddle.net/VolatileStorm/aNk6e/

我提出的解决方案是,可拖动对象应该使用绝对而不是相对定位,但是我找不到解决方法.有没有办法做到这一点,如果没有,有人可以想办法解决吗? (为求优雅,我不会接受不要删除其他可拖动对象").

My proposed solution is that the draggable should be using absolute as opposed to relative positioning, however I can't find a way to do this. Is there a way to do this, and if not, can anyone think of a way around it? (For elegance's sake, I won't accept "don't delete the other draggable").

推荐答案

为什么 position:absolute 不能为您工作?

Why doesn't position:absolute work for you?

由于绝对定位的元素不再属于文档流的一部分,因此,三个<div>中的每一个都放置在其包含(定位)元素的0,0处.因此,您可以确定可拖动对象的起始位置.

Since absolutely positioned elements are no longer part of the document flow, each of your three <div>s are placed at 0,0 of its containing (positioned) element. Thus, it's up to you to work out the starting position of your draggables.

这篇关于jQuery UI可拖动的绝对绝对值而不是相对值?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

05-29 07:17