How do I know the IntersectionObserver scroll direction?

后端 未结 5 2034
半阙折子戏
半阙折子戏 2020-12-07 18:48

So, how do I know the scroll direction when the event it\'s triggered?

In the returned object the closest possibility I see is interacting with the boundingCli

5条回答
  •  不思量自难忘°
    2020-12-07 19:28

    :)

    I don't think this is possible with a single threshold value. You could try to watch out for the intersectionRatio which in most of the cases is something below 1 when the container leaves the viewport (because the intersection observer fires async). I'm pretty sure that it could be 1 too though if the browser catches up quickly enough. (I didn't test this :D )

    But what you maybe could do is observe two thresholds by using several values. :)

    threshold: [0.9, 1.0]
    

    If you get an event for the 0.9 first it's clear that the container enters the viewport...

    Hope this helps. :)

提交回复
热议问题