Back to Content

VisualViewport: scroll event

files/en-us/web/api/visualviewport/scroll_event/index.md

latest769 B
Original Source

{{APIRef("CSSOM view API")}}

The scroll event of the {{domxref("VisualViewport")}} interface is fired when the visual viewport is scrolled. This allows you to position elements relative to the visual viewport as it is scrolled, which would normally be anchored to the layout viewport.

Syntax

Use the event name in methods like {{domxref("EventTarget.addEventListener", "addEventListener()")}}, or set an event handler property.

js-nolint
addEventListener("scroll", (event) => { })

onscroll = (event) => { }

Event type

A generic {{domxref("Event")}}.

Examples

See the VisualViewport landing page for a usage demo.

Specifications

{{Specifications}}

Browser compatibility

{{Compat}}