如何使用 iScroll 同时滚动 2 个 div

发布于 2024-12-26 12:48:47 字数 91 浏览 3 评论 0原文

我有 2 个 div 都使用 iScroll。现在我希望两个 div 在其中一个 div 滚动时也滚动。

我希望它们同时滚动

这可能吗?

I have 2 divs that both uses iScroll. Now I would like both divs to scroll when one of them are scrolled.

I want them to scroll simultaneously

Is this possible?

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

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

发布评论

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

评论(2

忆梦 2025-01-02 12:48:47

您可以使用 scrollTo 方法在滚动任何 div 时将第二个 div 滚动到指定位置。它需要三个参数,其中超时是可选的。

scrollTo(x, y, timeout) - 滚动到滚动区域内的任何 x,y 位置。

You can use scrollTo method to scroll the second div at a specified position on scrolling any div. It takes three arugments out of which timeout is optional.

scrollTo(x, y, timeout) - scrolls to any x,y location inside the scrolling area.

ぶ宁プ宁ぶ 2025-01-02 12:48:47

尝试按如下方式构造 div

<div id=wrapper>
 <div id="scroller">
   <div id="div1">
     <div id="child1"></div>
   </div>
   <div id="div2">
     <div id="child2"></div>
   </div>
 </div>
</div>

然后为 #wrapper 定义 iscroll,然后您就可以同时滚动两个 div。这是最简单的方法。

或者您可以尝试获取onScroll 事件。虽然在滚动过程中不可能准确地到达滚动位置,但您仍然可以在 onScrollMoveonScrollEnd 上获得 is in。希望这对您有帮助。

Try structuring the div as follows :

<div id=wrapper>
 <div id="scroller">
   <div id="div1">
     <div id="child1"></div>
   </div>
   <div id="div2">
     <div id="child2"></div>
   </div>
 </div>
</div>

Then define iscroll for #wrapper and you get to scroll both the div simultaneously. This is the easy way.

Or you can try to get the onScroll event. Though it is not possible to exactly get on scroll position during scroll but you can still get is in on onScrollMove and onScrollEnd. Hope this helps you.

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