gpt4 book ai didi

javascript - 滚动容器时拖动元素出错

转载 作者:行者123 更新时间:2023-11-29 19:29:20 29 4
gpt4 key购买 nike

在此Fiddle ,我让红色容器可以拖动。如您所见,这工作正常,但是当绿色容器(父容器)滚动一点然后拖动红色容器时,拖动没有发生在正确的位置。

谁能告诉我可能是什么问题?

我尝试了 e.pageXe.clientXe.offsetX 但仍然无法解决这个问题。 (或者我错过了什么)

最佳答案

您需要将滚动顶部位置添加到您的形状中。如果您希望您的正方形保持在正确的位置,请检查:

function repositionShape(e) {
$self = repositionStart.self;
$commentSection = repositionStart.commentSection;

var dy = $('.wrapper').scrollTop(); // Get wrapper scroll position

$self.css({
'left': e.clientX - repositionStart.offset.left,
'top': e.clientY - repositionStart.offset.top +dy // Add delta to your square position
});
}

关于javascript - 滚动容器时拖动元素出错,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28965414/

29 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com