Socket
Book a DemoInstallSign in
Socket

@juo/visual-intersection-observer

Package Overview
Dependencies
Maintainers
1
Versions
3
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@juo/visual-intersection-observer

Source
npmnpm
Version
0.0.0
Version published
Maintainers
1
Created
Source

Visual Intersection Observer

Problem

There is a great Intersection Observer API that allows among others to observe if elements are present in the viewport or not. The missing part in the before-mentioned API is that under no circumstances one can use Visual Viewport as the root for the IntersectionObserver. At the time of writing this there is an open discussion regarding the issue here.

In other words IntersectionObserver works great as long as user does not zoom the website in or out, as soon as it happens the intersections reported by the IntersectionObserver are invalid.

Solution

An Visual Intersection Observer that acts as a wrapping utility for the Intersection Observer that modifies the rootMargin appropriately to the Visual Viewport.

See the demo to see it in action.

Known issues

  • When document width is larger than the viewport intersection is not computed properly on mobile devices
  • Chrome and Firefox on mobile sometimes report an incorrect width/height of the Visual Viewport

FAQs

Package last updated on 13 May 2022

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts