VisualViewport Class

The visual viewport of a document (https://drafts.csswg.org/cssom-view/#the-visualviewport-interface): there is no pinch zoom, so it is the layout viewport without its scrollbars (the initial containing block computed by the layout: the clientWidth and clientHeight of the root element), a scale of 1, no offset from the layout viewport, and the scroll position of the layout viewport as page offsets. It is never scrolled relative to the layout viewport, so it never fires scroll nor scrollend events; it fires resize events when its size changes (the size of the viewport, or its classic scrollbars).

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, there is no pinch zoom.
OffsetTopGets the offset of the top edge of the visual viewport from the top edge of the layout viewport: 0, there is no pinch zoom.
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), else 1 (there is no pinch zoom), 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, there is no pinch zoom.

public double OffsetLeft { get; }

Gets the offset of the top edge of the visual viewport from the top edge of the layout viewport: 0, there is no pinch zoom.

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), else 1 (there is no pinch zoom), 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; }