scroll-view组件的scroll-into-view是否可以逆向操作?

小程序 文章 2021-03-04 12:21 612 0 全屏看文

AI助手支持GPT4.0

scroll-view组件的scroll-into-view是否可以逆向操作?Can the scroll-into-view of the scroll-view component be operated in reverse?

scroll-view组件的scroll-into-view是否可以逆向操作?

在做这样一个项目的时候,右边是一个scroll-view组件,给每一个标题盒子设置了不同的ID。在点击左边nav的选项的时候,利用scroll-into-view属性给他赋值相应的ID,右边可以滚动到相应的盒子,这是可以实现的。但是,在不点击左边选项的情况下,手动滚动右边的商品,在滚动到相应ID盒子的时候是否能监听到滚到哪个ID呢?我在@scroll里面没有找到,有是有ID字段,但是是空的值,我想请问一下是我姿势不对吗?还是说只能通过商品数量*高度去算滚到哪了?

When doing such a project, there is a scroll view component on the right, which sets different IDs for each title box. When you click the NAV option on the left, use the scroll into view attribute to assign the corresponding ID to it. You can scroll to the corresponding box on the right, which is realizable. However, without clicking the option on the left, if you manually scroll to the item on the right, can you monitor which id you scroll to when you scroll to the corresponding ID box? I didn't find it in @ scroll. There is an ID field, but it's an empty value. I want to ask if my posture is wrong? Or can we only calculate the roll by the quantity * height of goods?

回答:

年轻乄霸道:

创建一个 IntersectionObserver 对象实例,去监听所有要触发的事件!比较容易实现该功能。

官方文档 二楼@卢霄霄 已发!





默垂眸:

没有方法 只能自己计算

右边滑动获取当前滚动的高度 然后通过计算和左边的对应起来

-EOF-

AI助手支持GPT4.0