VisualViewport Class

The visual viewport of a document (https://drafts.csswg.org/cssom-view/#the-visualviewport-interface): the layout viewport without its scrollbars (the initial containing block computed by the layout: the clientWidth and clientHeight of the root element), magnified by the pinch zoom of the user (see UserInput.Pinch). Only the visual viewport of a top-level document is zoomed: it is then smaller than the layout viewport, and it is scrolled in the layout viewport (its VisualViewport.OffsetLeft and VisualViewport.OffsetTop) by the scrolls of the user, before the layout viewport. It fires scroll and scrollend events when its offset changes, and resize events when its size changes (the size of the viewport, its classic scrollbars, or the pinch zoom).

public sealed class VisualViewport : EventTarget
Inheritance
EventTarget VisualViewport

Properties

NameDescription
HeightGets the height of the visual viewport (https://drafts.csswg.org/cssom-view/#dom-visualviewport-height): see VisualViewport.Width.
OffsetLeftGets the offset of the left edge of the visual viewport from the left edge of the layout viewport: 0 unless the user zoomed in (see UserInput.Pinch), or 0 when the document is not fully active.
OffsetTopGets the offset of the top edge of the visual viewport from the top edge of the layout viewport: see VisualViewport.OffsetLeft.
OnResizeGets or sets the event handler of the resize event.
OnScrollGets or sets the event handler of the scroll event.
OnScrollEndGets or sets the event handler of the scrollend event.
PageLeftGets the x coordinate of the left edge of the visual viewport relative to the initial containing block: the scroll position of the layout viewport plus VisualViewport.OffsetLeft (Window.ScrollX), or 0 when the document is not fully active.
PageTopGets the y coordinate of the top edge of the visual viewport relative to the initial containing block: see VisualViewport.PageLeft.
ScaleGets the scale of the visual viewport: the page scale of a top-level document on a mobile device (set by its viewport meta element, see ViewportOptions.IsMobile) multiplied by the pinch zoom of the user (see UserInput.Pinch), or 0 when the document is not fully active.
WidthGets the width of the visual viewport (https://drafts.csswg.org/cssom-view/#dom-visualviewport-width): the width of the viewport without the rendered vertical classic scrollbar, divided by VisualViewport.Scale (the layout is computed when it is out of date), or 0 when the document is not fully active. On a mobile device (ViewportOptions.IsMobile), the visual viewport of a top-level document is the viewport of the device scaled by the page scale.

Gets the height of the visual viewport (https://drafts.csswg.org/cssom-view/#dom-visualviewport-height): see VisualViewport.Width.

public double Height { get; }

Gets the offset of the left edge of the visual viewport from the left edge of the layout viewport: 0 unless the user zoomed in (see UserInput.Pinch), or 0 when the document is not fully active.

public double OffsetLeft { get; }

Gets the offset of the top edge of the visual viewport from the top edge of the layout viewport: see VisualViewport.OffsetLeft.

public double OffsetTop { get; }

Gets or sets the event handler of the resize event.

public Action<Event>? OnResize { get; set; }

Gets or sets the event handler of the scroll event.

public Action<Event>? OnScroll { get; set; }

Gets or sets the event handler of the scrollend event.

public Action<Event>? OnScrollEnd { get; set; }

Gets the x coordinate of the left edge of the visual viewport relative to the initial containing block: the scroll position of the layout viewport plus VisualViewport.OffsetLeft (Window.ScrollX), or 0 when the document is not fully active.

public double PageLeft { get; }

Gets the y coordinate of the top edge of the visual viewport relative to the initial containing block: see VisualViewport.PageLeft.

public double PageTop { get; }

Gets the scale of the visual viewport: the page scale of a top-level document on a mobile device (set by its viewport meta element, see ViewportOptions.IsMobile) multiplied by the pinch zoom of the user (see UserInput.Pinch), or 0 when the document is not fully active.

public double Scale { get; }

Gets the width of the visual viewport (https://drafts.csswg.org/cssom-view/#dom-visualviewport-width): the width of the viewport without the rendered vertical classic scrollbar, divided by VisualViewport.Scale (the layout is computed when it is out of date), or 0 when the document is not fully active. On a mobile device (ViewportOptions.IsMobile), the visual viewport of a top-level document is the viewport of the device scaled by the page scale.

public double Width { get; }