jQuery拖放位置错误

发布于 2024-10-07 22:44:11 字数 307 浏览 0 评论 0原文

最近我在 jQuery 上的拖放陷入了死胡同。

我在 div 容器内有一些 div 元素,所有这些元素 使用 top 和 left css 属性定位。其中一些元素 必须保持隐藏(css display:none)并且当特定事件触发时, 必须显示一些隐藏的元素。到目前为止我们都很好,因为 即使元素被隐藏,当它们显示时,它们所在的位置 他们被给予了顶部和左侧的正确位置。问题 当拖动先前隐藏的元素之一进行定位时开始 到其他地方;由于某些奇怪的原因,当拖动开始时,元素 它不是固定在光标位置,而是位于光标下方 300px 向左 200px。为什么会发生这种情况,我该如何解决这个问题?

Recently I have come to a dead end with the drag and drop on jQuery.

I have some div elements inside of a div container, all of this elements
are positioned using top and left css attributes. Some of this elements
must remain hidden (css display:none) and when a specific event triggers,
some of the hidden elements must be displayed. So far we are good, because
even though the elements were hidden, when they are shown they are located
on their correct spots with the top and left they were given. The problem
starts when one of this previously hidden elements are dragged to be positioned
to some other place; for some odd reason when the drag starts, the element
instead of stick to the cursor position, it goes like 300px below the cursor
and 200px to the left. Why is this happening, how can I solve the problem?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

网白 2024-10-14 22:44:11

我还没有使用过可拖动对象,但网站说......

要在拖动过程中操纵可拖动对象的位置,您可以使用包装器作为可拖动帮助器并使用绝对定位来定位包装元素,也可以像这样更正内部值:

$(this).data('draggable').offset.click.top -= x

您还可以将样式应用于 。 ui-draggable-dragging 类,但这只是一个创可贴。

I haven't used draggable objects yet, but the website says...

To manipulate the position of a draggable during drag, you can either use a wrapper as the draggable helper and position the wrapped element with absolute positioning, or you can correct internal values like so:

$(this).data('draggable').offset.click.top -= x

You can also apply a style to the .ui-draggable-dragging class, but that's only a band-aid.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文