gpt4 book ai didi

javascript - 在 div 内拖动而不是滚动

转载 作者:行者123 更新时间:2023-11-29 10:47:01 25 4
gpt4 key购买 nike

我正在尝试弄清楚如何让用户拖动图像而不是必须向右滚动(参见 here)

它按照我希望的方式工作:

$("#timeline").draggable({
axis: "x",
});

问题是当用户到达图像的末尾时,他们仍然可以继续拖动而不是停止拖动。

有没有更有效的方法,当它到达末尾时就像用户滚动到末尾时一样停止?

最佳答案

将回调添加到 draggable 以检查页面宽度与图像宽度的比较以及它在页面上的位置。

类似于:

$("#timeline").draggable({
axis: "x",
drag: function(event, ui){
var position = ui.position;
var offset = ui.offset;
//code returns false if your check does not go through
//your code to check if the user can drag anymore
}
});

关于javascript - 在 div 内拖动而不是滚动,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17656120/

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