1. Background
Many of the features defined in this specification have been supported by browsers for a long period of time. The goal of this specification is to define these features in such a way that they can be implemented by all browsers in an interoperable manner. The specification also defines a some new features which allow for scroll customization.
2. Terminology
Terminology used in this specification is from DOM, CSSOM and HTML. [DOM] [CSSOM] [HTML]
An element body (which will be the body
element) is potentially scrollable if all of the following conditions are true:
-
body has an associated box.
-
body’s parent element’s computed value of the overflow-x or overflow-y properties is neither visible nor clip.
-
body’s computed value of the overflow-x or overflow-y properties is neither visible nor clip.
Note: A body
element that is potentially scrollable might not have a scrolling box.
For instance, it could have a used value of overflow being auto but not have its content overflowing its content area.
A scrolling box of a viewport or element has two overflow directions, which are the block-end and inline-end directions for that viewport or element. Note that the initial scroll position might not be aligned with the scrolling area origin depending on the content-distribution properties, see CSS Box Alignment 3 § 5.3 Overflow and Scroll Positions.
The term scrolling area refers to a box of a viewport or an element that has the following edges, depending on the viewport’s or element’s scrolling box’s overflow directions.
If the overflow directions are… | For a viewport | For an element |
---|---|---|
rightward and downward |
|
|
leftward and downward |
|
|
leftward and upward |
|
|
rightward and upward |
|
|
The origin of a scrolling area is the origin of the initial containing block if the scrolling area is a viewport, and otherwise the top left padding edge of the element when the element has its default scroll position. The x-coordinate increases rightwards, and the y-coordinate increases downwards.
The beginning edges of a particular set of edges of a box or element are the following edges:
- If the overflow directions are rightward and downward
- The top and left edges.
- If the overflow directions are leftward and downward
- The top and right edges.
- If the overflow directions are leftward and upward
- The bottom and right edges.
- If the overflow directions are rightward and upward
- The bottom and left edges.
The ending edges of a particular set of edges of a box or element are the following edges:
- If the overflow directions are rightward and downward
- The bottom and right edges.
- If the overflow directions are leftward and downward
- The bottom and left edges.
- If the overflow directions are leftward and upward
- The top and left edges.
- If the overflow directions are rightward and upward
- The top and right edges.
The visual viewport is a kind of viewport whose scrolling area is another viewport, called the layout viewport.
In addition to scrolling, the visual viewport may also apply a scale transform to its layout viewport. This transform is applied to the canvas of the layout viewport and does not affect its internal coordinate space.
Note: The scale transform of the visual viewport is often referred to as "pinch-zoom". Conceptually, this transform changes the size of the CSS reference pixel but changes the size of the layout viewport proportionally so that it does not cause reflow of the page’s contents.
The magnitude of the scale transform is known as the visual viewport’s scale factor.
The VisualViewport
object has an associated document, which is a Document
object.
It is the associated document of the owner Window
of VisualViewport
. The layout viewport is the owner Window
's viewport.
For the purpose of the requirements in this specification, elements that have a computed value of the display property that is table-column or table-column-group must be considered to have an associated box (the column or column group, respectively).
The term SVG layout box refers to a box generated by an SVG element
which does not correspond to a CSS-defined display type.
(Such as the box generated by a rect
element.)
The term transforms refers to SVG transforms and CSS transforms. [SVG11] [CSS-TRANSFORMS-1]
When a method or an attribute is said to call another method or attribute, the user agent must invoke its internal API for that attribute or method so that e.g. the author can’t change the behavior by overriding attributes or methods with custom properties or functions in ECMAScript.
Unless otherwise stated, all string comparisons use is.
2.1. CSS pixels
All coordinates and dimensions for the APIs defined in this specification are in CSS pixels, unless otherwise specified. [CSS-VALUES]
Note: This does not apply to e.g. matchMedia()
as the units are explicitly given there.
2.2. Zooming
There are two kinds of zoom, page zoom which affects the size of the initial viewport, and the visual viewport scale factor which acts like a magnifying glass and does not affect the initial viewport or actual viewport. [CSS-DEVICE-ADAPT]
Note: The "scale factor" is often referred to as "pinch-zoom"; however, it can be affected through means other than pinch-zooming. e.g. The user agent may zooms in on a focused input element to make it legible.
2.3. Web-exposed screen information
User agents may choose to hide information about the screen of the output device, in order to protect the user’s privacy. In order to do so in a consistent manner across APIs, this specification defines the following terms, each having a width and a height, the origin being the top left corner, and the x- and y-coordinates increase rightwards and downwards, respectively.
The Web-exposed screen area is one of the following:
-
The area of the output device, in CSS pixels.
-
The area of the viewport, in CSS pixels.
The Web-exposed available screen area is one of the following:
-
The available area of the rendering surface of the output device, in CSS pixels.
-
The area of the output device, in CSS pixels.
-
The area of the viewport, in CSS pixels.
3. Common Infrastructure
This specification depends on the WHATWG Infra standard. [INFRA]
3.1. Scrolling
When a user agent is to perform a scroll of a scrolling box box,
to a given position position,
an associated element element and optionally a scroll behavior behavior (which is "auto
" if omitted),
the following steps must be run:
- Abort any ongoing smooth scroll for box.
-
If the user agent honors the scroll-behavior property and one of the following are true:
- behavior is "
auto
" and element is not null and its computed value of the scroll-behavior property is smooth - behavior is
smooth
Note: If the scroll position did not change as a result of the user interaction or programmatic invocation, where no translations were applied as a result, then no scrollend event fires because no scrolling occured.
- behavior is "
Scroll is completed when the scroll position has no more pending updates or translations and the user has completed their gesture. Scroll position updates include smooth or instant mouse wheel scrolling, keyboard scrolling, scroll-snap events, or other APIs and gestures which cause the scroll position to update and possibly interpolate. User gestures like touch panning or trackpad scrolling aren’t complete until pointers or keys have released.
When a user agent is to perform a smooth scroll of a scrolling box box to position, it must update the scroll position of box in a user-agent-defined fashion over a user-agent-defined amount of time. When the scroll is completed, the scroll position of box must be position. The scroll can also be aborted, either by an algorithm or by the user.
When a user agent is to perform an instant scroll of a scrolling box box to position, it must update the scroll position of box to position.
To scroll to the beginning of the document for a document document, follow these steps:
- Let viewport be the viewport that is associated with document.
- Let position be the scroll position viewport would have by aligning the beginning edges of the scrolling area with the beginning edges of viewport.
- If position is the same as viewport’s current scroll position, and viewport does not have an ongoing smooth scroll, abort these steps.
- Perform a scroll of viewport to position, and document’s root element as the associated element, if there is one, or null otherwise.
Note: This algorithm is used when navigating to the #top
fragment identifier, as defined in HTML. [HTML]
3.2. WebIDL values
When asked to normalize non-finite values for a value x,
if x is one of the three special floating point literal values
(Infinity
, -Infinity
or NaN
),
then x must be changed to the value 0
. [WEBIDL]
4. Extensions to the Window
Interface
enum {
ScrollBehavior ,
"auto" };
"smooth" dictionary {
ScrollOptions ScrollBehavior = "auto"; };
behavior dictionary :
ScrollToOptions ScrollOptions {unrestricted double ;
left unrestricted double ; };
top partial interface Window { [NewObject ]MediaQueryList matchMedia (CSSOMString ); [
query SameObject ,Replaceable ]readonly attribute Screen screen ; [SameObject ,Replaceable ]readonly attribute VisualViewport ?visualViewport ; // browsing contextundefined moveTo (long ,
x long );
y undefined moveBy (long ,
x long );
y undefined resizeTo (long ,
width long );
height undefined resizeBy (long ,
x long ); // viewport [
y Replaceable ]readonly attribute long innerWidth ; [Replaceable ]readonly attribute long innerHeight ; // viewport scrolling [Replaceable ]readonly attribute double scrollX ; [Replaceable ]readonly attribute double pageXOffset ; [Replaceable ]readonly attribute double scrollY ; [Replaceable ]readonly attribute double pageYOffset ;undefined scroll (optional ScrollToOptions = {});
options undefined scroll (unrestricted double ,
x unrestricted double );
y undefined scrollTo (optional ScrollToOptions = {});
options undefined scrollTo (unrestricted double ,
x unrestricted double );
y undefined scrollBy (optional ScrollToOptions = {});
options undefined scrollBy (unrestricted double ,
x unrestricted double ); // client [
y Replaceable ]readonly attribute long screenX ; [Replaceable ]readonly attribute long screenLeft ; [Replaceable ]readonly attribute long screenY ; [Replaceable ]readonly attribute long screenTop ; [Replaceable ]readonly attribute long outerWidth ; [Replaceable ]readonly attribute long outerHeight ; [Replaceable ]readonly attribute double devicePixelRatio ; };
In all current engines.
Opera12.1+Edge79+
Edge (Legacy)12+IE10+
Firefox for Android?iOS Safari?Chrome for Android?Android WebView3+Samsung Internet?Opera Mobile12.1+
When the matchMedia(query)
method is invoked these steps must be run:
- Let parsed media query list be the result of parsing query.
- Return a new
MediaQueryList
object, with this's associatedDocument
as the document, with parsed media query list as its associated media query list.
In all current engines.
Opera12.1+Edge79+
Edge (Legacy)12+IE4+
Firefox for Android?iOS Safari?Chrome for Android?Android WebView?Samsung Internet?Opera Mobile12.1+
The screen
attribute must return the Screen
object
associated with the Window
object.
Note: Accessing screen
through a WindowProxy
object might yield different
results when the Document
is navigated.
In all current engines.
Opera?Edge79+
Edge (Legacy)?IENone
Firefox for Android68+iOS Safari?Chrome for Android?Android WebView?Samsung Internet?Opera Mobile?
If the associated document is fully active, the visualViewport
attribute must return the VisualViewport
object associated with the Window
object’s associated
document. Otherwise, it must return null.
Note: the VisualViewport object is only returned and useful for a window whose Document is currently being presented. If a reference is retained to a VisualViewport whose associated Document is not being currently presented, the values in that VisualViewport must not reveal any information about the browsing context.
In all current engines.
Opera12.1+Edge79+
Edge (Legacy)12+IE4+
Firefox for Android?iOS Safari?Chrome for Android?Android WebView?Samsung Internet?Opera Mobile12.1+
The moveTo(x, y)
method must follow these steps:
-
Optionally, return.
-
Let target be this's relevant global object's browsing context.
-
If target is not an auxiliary browsing context that was created by a script (as opposed to by an action of the user), then return.
-
Optionally, clamp x and y in a user-agent-defined manner so that the window does not move outside the available space.
-
Move target’s window such that the window’s top left corner is at coordinates (x, y) relative to the top left corner of the output device, measured in CSS pixels of target. The positive axes are rightward and downward.
In all current engines.
Opera12.1+Edge79+
Edge (Legacy)12+IE4+
Firefox for Android?iOS Safari?Chrome for Android?Android WebView?Samsung Internet?Opera Mobile12.1+
The moveBy(x, y)
method must follow these steps:
-
Optionally, return.
-
Let target be this's relevant global object's browsing context.
-
If target is not an auxiliary browsing context that was created by a script (as opposed to by an action of the user), then return.
-
Optionally, clamp x and y in a user-agent-defined manner so that the window does not move outside the available space.
-
Move target’s window x CSS pixels of target rightward and y CSS pixels of target downward.
In all current engines.
Opera12.1+Edge79+
Edge (Legacy)12+IE4+
Firefox for Android4+iOS Safari?Chrome for Android?Android WebView?Samsung Internet?Opera Mobile12.1+
The resizeTo(width, height)
method must follow these steps:
-
Optionally, return.
-
Let target be this's relevant global object's browsing context.
-
If target is not an auxiliary browsing context that was created by a script (as opposed to by an action of the user), then return.
-
Optionally, clamp width and height in a user-agent-defined manner so that the window does not get too small or bigger than the available space.
-
Resize target’s window by moving its right and bottom edges such that the distance between the left and right edges of the viewport are width CSS pixels of target and the distance between the top and bottom edges of the viewport are height CSS pixels of target.
-
Optionally, move target’s window in a user-agent-defined manner so that it does not grow outside the available space.
In all current engines.
Opera12.1+Edge79+
Edge (Legacy)12+IE4+
Firefox for Android4+iOS Safari?Chrome for Android?Android WebView?Samsung Internet?Opera Mobile12.1+
The resizeBy(x, y)
method must follow these steps:
-
Optionally, return.
-
Let target be this's relevant global object's browsing context.
-
If target is not an auxiliary browsing context that was created by a script (as opposed to by an action of the user), then return.
-
Optionally, clamp x and y in a user-agent-defined manner so that the window does not get too small or bigger than the available space.
-
Resize target’s window by moving its right edge x CSS pixels of target rightward and its bottom edge y CSS pixels of target downward.
-
Optionally, move target’s window in a user-agent-defined manner so that it does not grow outside the available space.
In all current engines.
Opera9+Edge79+
Edge (Legacy)12+IE9+
Firefox for Android4+iOS Safari1+Chrome for Android?Android WebView?Samsung Internet?Opera Mobile10.1+
The innerWidth
attribute must return the viewport width including the size of a rendered
scroll bar (if any), or zero if there is no viewport.
In all current engines.
Opera9+Edge79+
Edge (Legacy)12+IE9+
Firefox for Android4+iOS Safari1+Chrome for Android?Android WebView?Samsung Internet?Opera Mobile10.1+
The innerHeight
attribute must return the viewport height including the size of a rendered
scroll bar (if any), or zero if there is no viewport.
In all current engines.
Opera9.6+Edge79+
Edge (Legacy)12+IENone
Firefox for Android?iOS Safari?Chrome for Android?Android WebView?Samsung Internet?Opera Mobile10.1+
The scrollX
attribute must return the x-coordinate,
relative to the initial containing block origin,
of the left of the viewport,
or zero if there is no viewport.
In all current engines.
Opera3+Edge79+
Edge (Legacy)12+IE9+
Firefox for Android?iOS Safari?Chrome for Android?Android WebView?Samsung Internet?Opera Mobile10.1+
The pageXOffset
attribute must return the value returned by the scrollX
attribute.
In all current engines.
Opera9.6+Edge79+
Edge (Legacy)12+IENone
Firefox for Android?iOS Safari?Chrome for Android?Android WebView?Samsung Internet?Opera Mobile10.1+
The scrollY
attribute must return the y-coordinate,
relative to the initial containing block origin,
of the top of the viewport,
or zero if there is no viewport.
In all current engines.
Opera3+Edge79+
Edge (Legacy)12+IE9+
Firefox for Android?iOS Safari?Chrome for Android?Android WebView?Samsung Internet?Opera Mobile10.1+
The pageYOffset
attribute must return the value returned by the scrollY
attribute.
In all current engines.
Opera3+Edge79+
Edge (Legacy)12+IE4+
Firefox for Android?iOS Safari?Chrome for Android?Android WebView?Samsung Internet?Opera Mobile10.1+
When the scroll()
method is invoked these
steps must be run:
-
If invoked with one argument, follow these substeps:
-
Let options be the argument.
-
Let x be the value of the
left
dictionary member of options, if present, or the viewport’s current scroll position on the x axis otherwise. -
Let y be the value of the
top
dictionary member of options, if present, or the viewport’s current scroll position on the y axis otherwise.
-
-
If invoked with two arguments, follow these substeps:
-
Let options be null converted to a
ScrollToOptions
dictionary. [WEBIDL] -
Let x and y be the arguments, respectively.
-
-
Normalize non-finite values for x and y.
-
If there is no viewport, abort these steps.
-
Let viewport width be the width of the viewport excluding the width of the scroll bar, if any.
-
Let viewport height be the height of the viewport excluding the height of the scroll bar, if any.
-
- If the viewport has rightward overflow direction
- Let x be max(0, min(x, viewport scrolling area width - viewport width)).
- If the viewport has leftward overflow direction
- Let x be min(0, max(x, viewport width - viewport scrolling area width)).
-
- If the viewport has downward overflow direction
- Let y be max(0, min(y, viewport scrolling area height - viewport height)).
- If the viewport has upward overflow direction
- Let y be min(0, max(y, viewport height - viewport scrolling area height)).
-
Let position be the scroll position the viewport would have by aligning the x-coordinate x of the viewport scrolling area with the left of the viewport and aligning the y-coordinate y of the viewport scrolling area with the top of the viewport.
-
If position is the same as the viewport’s current scroll position, and the viewport does not have an ongoing smooth scroll, abort these steps.
-
Let document be the viewport’s associated
Document
. -
Perform a scroll of the viewport to position, document’s root element as the associated element, if there is one, or null otherwise, and the scroll behavior being the value of the
behavior
dictionary member of options.
In all current engines.
Opera4+Edge79+
Edge (Legacy)12+IE4+
Firefox for Android?iOS Safari?Chrome for Android?Android WebView?Samsung Internet?Opera Mobile10.1+
When the scrollTo()
method is invoked, the
user agent must act as if the scroll()
method was invoked with the same arguments.
In all current engines.
Opera3+Edge79+
Edge (Legacy)12+IE11
Firefox for Android?iOS Safari?Chrome for Android?Android WebView?Samsung Internet?Opera Mobile10.1+
When the scrollBy()
method is invoked, the
user agent must run these steps:
-
If invoked with two arguments, follow these substeps:
-
Let options be null converted to a
ScrollToOptions
dictionary. [WEBIDL] -
Let x and y be the arguments, respectively.
-
Let the
left
dictionary member of options have the value x. -
Let the
top
dictionary member of options have the value y.
-
-
Normalize non-finite values for the
left
andtop
dictionary members of options. -
Act as if the
scroll()
method was invoked with options as the only argument.
In all current engines.
Opera12.1+Edge79+
Edge (Legacy)12+IE5+
Firefox for Android?iOS Safari?Chrome for Android?Android WebView?Samsung Internet?Opera Mobile12.1+
In all current engines.
Opera12.1+Edge79+
Edge (Legacy)12+IE9+
Firefox for Android?iOS Safari?Chrome for Android?Android WebView?Samsung Internet?Opera Mobile12.1+
The screenX
and screenLeft
attributes must return the x-coordinate,
relative to the origin of the Web-exposed screen area, of the left of
the client window as number of CSS pixels, or zero if there is no such
thing.
In all current engines.
Opera12.1+Edge79+
Edge (Legacy)12+IE5+
Firefox for Android?iOS Safari?Chrome for Android?Android WebView?Samsung Internet?Opera Mobile12.1+
In all current engines.
Opera12.1+Edge79+
Edge (Legacy)12+IE9+
Firefox for Android?iOS Safari?Chrome for Android?Android WebView?Samsung Internet?Opera Mobile12.1+
The screenY
and screenTop
attributes must return the y-coordinate,
relative to the origin of the screen of the Web-exposed screen area, of the top of
the client window as number of CSS pixels, or zero if there is no such
thing.
In all current engines.
Opera9+Edge79+
Edge (Legacy)12+IE9+
Firefox for Android?iOS Safari3+Chrome for Android?Android WebView?Samsung Internet?Opera Mobile10.1+
The outerWidth
attribute must return the width of the
client window. If there is no client window this
attribute must return zero.
In all current engines.
Opera9+Edge79+
Edge (Legacy)12+IE9+
Firefox for Android?iOS Safari3+Chrome for Android?Android WebView?Samsung Internet?Opera Mobile10.1+
The outerHeight
attribute must return the height of the
client window. If there is no client window this
attribute must return zero.
In all current engines.
Opera11.1+Edge79+
Edge (Legacy)12+IE11
Firefox for Android?iOS Safari1+Chrome for Android?Android WebView?Samsung Internet?Opera Mobile11.1+
The devicePixelRatio
attribute must return the result of the following determine the device pixel ratio algorithm:
-
If there is no output device, return 1 and abort these steps.
-
Let CSS pixel size be the size of a CSS pixel at the current page zoom and using a scale factor of 1.0.
-
Let device pixel size be the vertical size of a device pixel of the output device.
-
Return the result of dividing CSS pixel size by device pixel size.
4.1. The features argument to the open()
method
In all current engines.
Opera3+Edge79+
Edge (Legacy)12+IE4+
Firefox for Android?iOS Safari?Chrome for Android?Android WebView?Samsung Internet?Opera Mobile10.1+
HTML defines the open()
method. This section defines behavior for position and size given
in the features argument. [HTML]
To set up browsing context features for a browsing context target given a map tokenizedFeatures:
-
Let x be null.
-
Let y be null.
-
Let width be null.
-
Let height be null.
-
If tokenizedFeatures["left"] exists:
-
Set x to the result of invoking the rules for parsing integers on tokenizedFeatures["left"].
-
If x is an error, set x to 0.
-
Optionally, clamp x in a user-agent-defined manner so that the window does not move outside the Web-exposed available screen area.
-
Optionally, move target’s window such that the window’s left edge is at the horizontal coordinate x relative to the left edge of the Web-exposed screen area, measured in CSS pixels of target. The positive axis is rightward.
-
-
If tokenizedFeatures["top"] exists:
-
Set y to the result of invoking the rules for parsing integers on tokenizedFeatures["top"].
-
If y is an error, set y to 0.
-
Optionally, clamp y in a user-agent-defined manner so that the window does not move outside the Web-exposed available screen area.
-
Optionally, move target’s window such that the window’s top edge is at the vertical coordinate y relative to the top edge of the Web-exposed screen area, measured in CSS pixels of target. The positive axis is downward.
-
-
If tokenizedFeatures["width"] exists:
-
Set width to the result of invoking the rules for parsing integers on tokenizedFeatures["width"].
-
If width is an error, set width to 0.
-
If width is not 0:
-
Optionally, clamp width in a user-agent-defined manner so that the window does not get too small or bigger than the Web-exposed available screen area.
-
Optionally, size target’s window by moving its right edge such that the distance between the left and right edges of the viewport are width CSS pixels of target.
-
Optionally, move target’s window in a user-agent-defined manner so that it does not grow outside the Web-exposed available screen area.
-
-
-
If tokenizedFeatures["height"] exists:
-
Set height to the result of invoking the rules for parsing integers on tokenizedFeatures["height"].
-
If height is an error, set height to 0.
-
If height is not 0:
-
Optionally, clamp height in a user-agent-defined manner so that the window does not get too small or bigger than the Web-exposed available screen area.
-
Optionally, size target’s window by moving its bottom edge such that the distance between the top and bottom edges of the viewport are height CSS pixels of target.
-
Optionally, move target’s window in a user-agent-defined manner so that it does not grow outside the Web-exposed available screen area.
-
-
A supported open()
feature name is one of the following:
- width
- The width of the viewport.
- height
- The height of the viewport.
- left
- The left position of the window.
- top
- The top position of the window.
4.2. The MediaQueryList
Interface
In all current engines.
Opera12.1+Edge79+
Edge (Legacy)12+IE10+
Firefox for Android?iOS Safari?Chrome for Android?Android WebView37+Samsung Internet?Opera Mobile12.1+
In all current engines.
Opera?Edge79+
Edge (Legacy)?IENone
Firefox for Android?iOS Safari?Chrome for Android?Android WebView?Samsung Internet?Opera Mobile?
This section integrates with the event loop defined in HTML. [HTML]
A MediaQueryList
object has an associated media query list and an associated document set on creation.
A MediaQueryList
object has an associated media which is the serialized form of the associated media query list.
A MediaQueryList
object has an associated matches state which is
true if the associated media query list matches the state of the document, and false otherwise.
When asked to evaluate media queries and report changes for a Document
doc, run these steps:
-
For each
MediaQueryList
object target that has doc as its document, in the order they were created, oldest first, run these substeps:- If target’s matches state has changed since the last time these steps were run, fire an event named change at target using
MediaQueryListEvent
, with itsisTrusted
attribute initialized to true, itsmedia
attribute initialized to target’s media, and itsmatches
attribute initialized to target’s matches state.
- If target’s matches state has changed since the last time these steps were run, fire an event named change at target using
function handleOrientationChange( event) { if ( event. matches) // landscape …else …} var mql= matchMedia( "(orientation:landscape)" ); mql. onchange= handleOrientationChange;
[Exposed =Window ]interface :
MediaQueryList EventTarget {readonly attribute CSSOMString media ;readonly attribute boolean matches ;undefined addListener (EventListener ?);
callback undefined removeListener (EventListener ?);
callback attribute EventHandler onchange ; };
In all current engines.
Opera12.1+Edge79+
Edge (Legacy)12+IE10+
Firefox for Android?iOS Safari?Chrome for Android?Android WebView37+Samsung Internet?Opera Mobile12.1+
The media
attribute must return
the associated media.
In all current engines.
Opera12.1+Edge79+
Edge (Legacy)12+IE10+
Firefox for Android?iOS Safari?Chrome for Android?Android WebView37+Samsung Internet?Opera Mobile12.1+
The matches
attribute must return
the associated matches state.
The addListener(callback)
method,
when invoked, must run these steps:
-
Add an event listener with this and an event listener whose type is
change
, and callback is callback.
The removeListener(callback)
method,
when invoked, must run these steps:
-
If this’s event listener list contains an event listener whose type is
change
, callback is callback, and capture is false, then remove an event listener with this and that event listener.
Note: This specification initially had a custom callback mechanism with addListener()
and removeListener()
, and the callback was invoked with the associated media query list as argument.
Now the normal event mechanism is used instead.
For backwards compatibility, the addListener()
and removeListener()
methods
are basically aliases for addEventListener()
and removeEventListener()
, respectively,
and the change
event masquerades as a MediaQueryList
.
The following are the event handlers (and their corresponding event handler event types) that must be supported,
as event handler IDL attributes, by all objects implementing the MediaQueryList
interface:
Event handler | Event handler event type |
---|---|
In all current engines.
Firefox55+Safari14+Chrome39+
Opera?Edge79+ Edge (Legacy)?IENone Firefox for Android?iOS Safari?Chrome for Android?Android WebView?Samsung Internet?Opera Mobile? onchange
| change |
MediaQueryListEvent/MediaQueryListEvent
In all current engines.
Opera?Edge79+
Edge (Legacy)?IENone
Firefox for Android?iOS Safari?Chrome for Android?Android WebView?Samsung Internet?Opera Mobile?
[Exposed =Window ]interface :
MediaQueryListEvent Event {(
constructor CSSOMString ,
type optional MediaQueryListEventInit = {});
eventInitDict readonly attribute CSSOMString media ;readonly attribute boolean matches ; };dictionary :
MediaQueryListEventInit EventInit {CSSOMString = "";
media boolean =
matches false ; };
In all current engines.
Opera?Edge79+
Edge (Legacy)?IENone
Firefox for Android?iOS Safari?Chrome for Android?Android WebView?Samsung Internet?Opera Mobile?
The media
attribute must return the value it was initialized to.
In all current engines.
Opera?Edge79+
Edge (Legacy)?IENone
Firefox for Android?iOS Safari?Chrome for Android?Android WebView?Samsung Internet?Opera Mobile?
The matches
attribute must return the value it was initialized to.
4.2.1. Event summary
This section is non-normative.
Event | Interface | Interesting targets | Description |
---|---|---|---|
change
| MediaQueryListEvent
| MediaQueryList
| Fired at the MediaQueryList when the matches state changes.
|
4.3. The Screen
Interface
In all current engines.
Opera12.1+Edge79+
Edge (Legacy)12+IE4+
Firefox for Android?iOS Safari?Chrome for Android?Android WebView?Samsung Internet?Opera Mobile12.1+
As its name suggests, the Screen
interface represents information about the screen of the output device.
[Exposed =Window ]interface {
Screen readonly attribute long availWidth ;readonly attribute long availHeight ;readonly attribute long width ;readonly attribute long height ;readonly attribute unsigned long colorDepth ;readonly attribute unsigned long pixelDepth ; };
In all current engines.
Opera12.1+Edge79+
Edge (Legacy)12+IE4+
Firefox for Android?iOS Safari?Chrome for Android?Android WebView?Samsung Internet?Opera Mobile12.1+
The availWidth
attribute must return the width of the Web-exposed
available screen area.
In all current engines.
Opera12.1+Edge79+
Edge (Legacy)12+IE4+
Firefox for Android?iOS Safari?Chrome for Android?Android WebView?Samsung Internet?Opera Mobile12.1+
The availHeight
attribute must return the height of the Web-exposed available screen area.
In all current engines.
Opera12.1+Edge79+
Edge (Legacy)12+IE4+
Firefox for Android?iOS Safari?Chrome for Android?Android WebView?Samsung Internet?Opera Mobile12.1+
The width
attribute must return the width of the Web-exposed
screen area.
In all current engines.
Opera12.1+Edge79+
Edge (Legacy)12+IE4+
Firefox for Android?iOS Safari?Chrome for Android?Android WebView?Samsung Internet?Opera Mobile12.1+
The height
attribute must return the height of the Web-exposed
screen area.
In all current engines.
Opera12.1+Edge79+
Edge (Legacy)12+IE4+
Firefox for Android?iOS Safari?Chrome for Android?Android WebView?Samsung Internet1.0+Opera Mobile12.1+
In all current engines.
Opera12.1+Edge79+
Edge (Legacy)12+IE9+
Firefox for Android?iOS Safari?Chrome for Android?Android WebView?Samsung Internet1.0+Opera Mobile12.1+
The colorDepth
and pixelDepth
attributes should return the number of bits
allocated to colors for a pixel in the output device, excluding the alpha
channel. If the user agent is not able to return the number of bits used by the
output device, it should return the closest estimation such as, for example, the
number of bits used by the frame buffer sent to the display or any internal
representation that would be the closest to the value the output device would
use. The user agent must return a value for these attributes at least equal to
the value of the color media feature multiplied by three. If the different
color components are not represented with the same number of bits, the returned
value may be greater than three times the value of the color media feature. If the user
agent does not know the color depth or does not want to return it for privacy
considerations, it should return 24.
Note: The colorDepth
and pixelDepth
attributes return the same value for
compatibility reasons.
Note: Some non-conforming implementations are known to return 32 instead of 24.
5. Extensions to the Document
Interface
In all current engines.
Opera3+Edge79+
Edge (Legacy)12+IE4+
Firefox for Android?iOS Safari?Chrome for Android?Android WebView37+Samsung Internet?Opera Mobile10.1+
partial interface Document {Element ?elementFromPoint (double ,
x double );
y sequence <Element >elementsFromPoint (double ,
x double );
y CaretPosition ?caretPositionFromPoint (double ,
x double );
y readonly attribute Element ?scrollingElement ; };
In all current engines.
Opera12.1+Edge79+
Edge (Legacy)12+IE4+
Firefox for Android?iOS Safari?Chrome for Android?Android WebView37+Samsung Internet?Opera Mobile12.1+
The elementFromPoint(x, y)
method must follow these steps:
-
If either argument is negative, x is greater than the viewport width excluding the size of a rendered scroll bar (if any), or y is greater than the viewport height excluding the size of a rendered scroll bar (if any), or there is no viewport associated with the document, return null and terminate these steps.
-
If there is a box in the viewport that would be a target for hit testing at coordinates x,y, when applying the transforms that apply to the descendants of the viewport, return the associated element and terminate these steps.
-
If the document has a root element, return the root element and terminate these steps.
-
Return null.
Note: The elementFromPoint()
method does not necessarily return the top-most painted element. For
instance, an element can be excluded from being a target for hit testing by using the pointer-events CSS property.
In all current engines.
Opera30+Edge79+
Edge (Legacy)NoneIENone
Firefox for Android?iOS Safari?Chrome for Android?Android WebView?Samsung Internet?Opera Mobile30+
The elementsFromPoint(x, y)
method must follow these steps:
-
Let sequence be a new empty sequence.
-
If either argument is negative, x is greater than the viewport width excluding the size of a rendered scroll bar (if any), or y is greater than the viewport height excluding the size of a rendered scroll bar (if any), or there is no viewport associated with the document, return sequence and terminate these steps.
-
For each box in the viewport, in paint order, starting with the topmost box, that would be a target for hit testing at coordinates x,y even if nothing would be overlapping it, when applying the transforms that apply to the descendants of the viewport, append the associated element to sequence.
-
If the document has a root element, and the last item in sequence is not the root element, append the root element to sequence.
-
Return sequence.
Document/caretPositionFromPoint
In only one current engine.
Opera?EdgeNone
Edge (Legacy)?IENone
Firefox for Android?iOS Safari?Chrome for Android?Android WebView?Samsung Internet?Opera Mobile?
The caretPositionFromPoint(x, y)
method must return the
result of running these steps:
-
If there is no viewport associated with the document, return null.
-
If either argument is negative, x is greater than the viewport width excluding the size of a rendered scroll bar (if any), y is greater than the viewport height excluding the size of a rendered scroll bar (if any) return null.
-
If at the coordinates x,y in the viewport no text insertion point indicator would have been inserted when applying the transforms that apply to the descendants of the viewport, return null.
-
If at the coordinates x,y in the viewport a text insertion point indicator would have been inserted in a text entry widget which is also a replaced element, when applying the transforms that apply to the descendants of the viewport, return a caret position with its properties set as follows:
- caret node
- The node corresponding to the text entry widget.
- caret offset
- The amount of 16-bit units to the left of where the text insertion point indicator would have inserted.
- caret range
- null
-
Otherwise, return a caret position where the caret range is a collapsed
Range
object for the position where the text insertion point indicator would have been inserted when applying the transforms that apply to the descendants of the viewport, and the other properties are set as follows:- caret node
- The start node of the caret range.
- caret offset
- The start offset of the caret range.
Note: The specifics of hit testing are out of scope of this
specification and therefore the exact details of elementFromPoint()
and caretPositionFromPoint()
are therefore too. Hit testing will hopefully be defined in a future
revision of CSS or HTML.
In all current engines.
Opera?Edge79+
Edge (Legacy)12+IENone
Firefox for Android?iOS Safari?Chrome for Android?Android WebView?Samsung Internet?Opera Mobile?
The scrollingElement
attribute, on getting, must run these steps:
-
If the
Document
is in quirks mode, follow these substeps:-
If the
body
element exists, and it is not potentially scrollable, return thebody
element and abort these steps.For this purpose, a value of overflow:clip on the the
body
element’s parent element must be treated as overflow:hidden. -
Return null and abort these steps.
-
-
If there is a root element, return the root element and abort these steps.
-
Return null.
Note: For non-conforming user agents that always use the quirks mode behavior for scrollTop
and scrollLeft
, the scrollingElement
attribute is expected to also always return the body
element (or null if it does not exist).
This API exists so that Web developers can use it to get the right element to use for scrolling APIs,
without making assumptions about a particular user agent’s behavior
or having to invoke a scroll to see which element scrolls the viewport.
Note: the body
element is different from HTML’s document.body
in that the latter can return a frameset
element.
5.1. The CaretPosition
Interface
In only one current engine.
Opera?EdgeNone
Edge (Legacy)?IENone
Firefox for Android?iOS Safari?Chrome for Android?Android WebView?Samsung Internet?Opera Mobile?
A caret position gives the position of a text insertion point indicator. It always has an associated caret node, caret offset, and caret range. It is represented by a CaretPosition
object.
[Exposed =Window ]interface {
CaretPosition readonly attribute Node offsetNode ;readonly attribute unsigned long offset ; [NewObject ]DOMRect ?getClientRect (); };
The offsetNode
attribute must return the caret node.
The offset
attribute must return the caret offset.
The getClientRect()
method must follow these steps,
aborting on the first step that returns a value:
-
If caret range is not null:
-
Let list be the result of invoking the
getClientRects()
method on the range. -
If list is empty, return null.
-
Return the
DOMRect
object in list at index 0.
-
-
If caret node is a text entry widget that is a replaced element, and that is in the document, return a
DOMRect
object for the caret in the widget as represented by the caret offset value. The transforms that apply to the element and its ancestors are applied. -
Return null.
Note: This DOMRect
object is not live.
6. Extensions to the Element
Interface
In all current engines.
Opera8+Edge79+
Edge (Legacy)12+IE4+
Firefox for Android?iOS Safari?Chrome for Android?Android WebView37+Samsung Internet?Opera Mobile10.1+
enum {
ScrollLogicalPosition ,
"start" ,
"center" ,
"end" };
"nearest" dictionary :
ScrollIntoViewOptions ScrollOptions {ScrollLogicalPosition = "start";
block ScrollLogicalPosition = "nearest"; };
inline dictionary {
CheckVisibilityOptions boolean =
checkOpacity false ;boolean =
checkVisibilityCSS false ; };partial interface Element {DOMRectList getClientRects (); [NewObject ]DOMRect getBoundingClientRect ();boolean checkVisibility (optional CheckVisibilityOptions = {});
options undefined scrollIntoView (optional (boolean or ScrollIntoViewOptions )= {});
arg undefined scroll (optional ScrollToOptions = {});
options undefined scroll (unrestricted double ,
x unrestricted double );
y undefined scrollTo (optional ScrollToOptions = {});
options undefined scrollTo (unrestricted double ,
x unrestricted double );
y undefined scrollBy (optional ScrollToOptions = {});
options undefined scrollBy (unrestricted double ,
x unrestricted double );
y attribute unrestricted double scrollTop ;attribute unrestricted double scrollLeft ;readonly attribute long scrollWidth ;readonly attribute long scrollHeight ;readonly attribute long clientTop ;readonly attribute long clientLeft ;readonly attribute long clientWidth ;readonly attribute long clientHeight ; };
In all current engines.
Opera9.5+Edge79+
Edge (Legacy)12+IE5+
Firefox for Android?iOS Safari?Chrome for Android?Android WebView2+Samsung Internet?Opera Mobile10.1+
The getClientRects()
method, when invoked, must return the result of the following algorithm:
-
If the element on which it was invoked does not have an associated box return an empty
DOMRectList
object and stop this algorithm. -
If the element has an associated SVG layout box return a
DOMRectList
object containing a singleDOMRect
object that describes the bounding box of the element as defined by the SVG specification, applying the transforms that apply to the element and its ancestors. -
Return a
DOMRectList
object containingDOMRect
objects in content order, one for each box fragment, describing its border area (including those with a height or width of zero) with the following constraints:-
Apply the transforms that apply to the element and its ancestors.
-
If the element on which the method was invoked has a computed value for the display property of table or inline-table include both the table box and the caption box, if any, but not the anonymous container box.
-
Replace each anonymous block box with its child box(es) and repeat this until no anonymous block boxes are left in the final list.
-
Note: The DOMRect
objects returned by getClientRects()
are not live.
In all current engines.
Opera9.5+Edge79+
Edge (Legacy)12+IE4+
Firefox for Android?iOS Safari3.2+Chrome for Android?Android WebView2+Samsung Internet?Opera Mobile10.1+
The getBoundingClientRect()
method, when
invoked on an element element, must return the result of getting the bounding box for element.
-
Let list be the result of invoking
getClientRects()
on element. -
If the list is empty return a
DOMRect
object whosex
,y
,width
andheight
members are zero. -
If all rectangles in list have zero width or height, return the first rectangle in list.
-
Otherwise, return a
DOMRect
object describing the smallest rectangle that includes all of the rectangles in list of which the height or width is not zero.
Note: The DOMRect
object returned by getBoundingClientRect()
is not live.
div
element in a document:
var example= document. getElementsByTagName( "div" )[ 0 ]. getBoundingClientRect(); var exampleWidth= example. width; var exampleHeight= example. height;
checkVisibility()
method
provides a set of simple checks
for whether an element is potentially "visible".
It defaults to a very simple and straightforward method
based on the box tree,
but allows for several additional checks to be opted into,
depending on what precise notion of "visibility" is desired.
The checkVisibility(options)
method
must run these steps,
when called on an element this:
-
If this does not have an associated box, return false.
-
If a shadow-including ancestor of this has content-visibility: hidden, return false.
-
If the
checkOpacity
dictionary member of options is true, and this, or a shadow-including ancestor of this, has a computed opacity value of 0, return false. -
If the
checkVisibilityCSS
dictionary member of options is true, and this is invisible, return false. -
Return true.
In all current engines.
Opera12.1+Edge79+
Edge (Legacy)NoneIENone
Firefox for Android?iOS Safari1+Chrome for Android?Android WebView?Samsung Internet?Opera Mobile12.1+
The scrollIntoView(arg)
method must run these steps:
-
Let behavior be "
auto
". -
Let block be "
start
". -
Let inline be "
nearest
". -
If arg is a
ScrollIntoViewOptions
dictionary, then: -
Otherwise, if arg is false, then set block to "
end
". -
If the element does not have any associated box, or is not available to user-agent features, then return.
-
Scroll the element into view with behavior, block, and inline.
-
Optionally perform some other action that brings the element to the user’s attention.
In all current engines.
Opera?Edge79+
Edge (Legacy)?IENone
Firefox for Android?iOS Safari?Chrome for Android?Android WebView?Samsung Internet?Opera Mobile?
The scroll()
method must run these steps:
-
If invoked with one argument, follow these substeps:
-
Let options be the argument.
-
Normalize non-finite values for
left
andtop
dictionary members of options, if present. -
Let x be the value of the
left
dictionary member of options, if present, or the element’s current scroll position on the x axis otherwise. -
Let y be the value of the
top
dictionary member of options, if present, or the element’s current scroll position on the y axis otherwise.
-
-
If invoked with two arguments, follow these substeps:
-
Let options be null converted to a
ScrollToOptions
dictionary. [WEBIDL] -
Let x and y be the arguments, respectively.
-
Normalize non-finite values for x and y.
-
Let the
left
dictionary member of options have the value x. -
Let the
top
dictionary member of options have the value y.
-
-
Let document be the element’s node document.
-
If document is not the active document, terminate these steps.
-
Let window be the value of document’s
defaultView
attribute. -
If window is null, terminate these steps.
-
If the element is the root element and document is in quirks mode, terminate these steps.
-
If the element is the root element invoke
scroll()
on window withscrollX
on window as first argument and y as second argument, and terminate these steps. -
If the element is the
body
element, document is in quirks mode, and the element is not potentially scrollable, invokescroll()
on window with options as the only argument, and terminate these steps. -
If the element does not have any associated box, the element has no associated scrolling box, or the element has no overflow, terminate these steps.
-
Scroll the element to x,y, with the scroll behavior being the value of the
behavior
dictionary member of options.
In all current engines.
Opera?Edge79+
Edge (Legacy)?IENone
Firefox for Android?iOS Safari?Chrome for Android?Android WebView?Samsung Internet?Opera Mobile?
When the scrollTo()
method is invoked, the
user agent must act as if the scroll()
method was invoked with the same arguments.
In all current engines.
Opera?Edge79+
Edge (Legacy)?IENone
Firefox for Android?iOS Safari?Chrome for Android?Android WebView?Samsung Internet?Opera Mobile?
When the scrollBy()
method is invoked, the
user agent must run these steps:
-
If invoked with one argument, follow these substeps:
-
Let options be the argument.
-
Normalize non-finite values for
left
andtop
dictionary members of options, if present.
-
-
If invoked with two arguments, follow these substeps:
-
Let options be null converted to a
ScrollToOptions
dictionary. [WEBIDL] -
Let x and y be the arguments, respectively.
-
Normalize non-finite values for x and y.
-
Let the
left
dictionary member of options have the value x. -
Let the
top
dictionary member of options have the value y.
-
-
Add the value of
scrollLeft
to theleft
dictionary member. -
Act as if the
scroll()
method was invoked with options as the only argument.
In all current engines.
Opera8+Edge79+
Edge (Legacy)12+IE5+
Firefox for Android?iOS Safari?Chrome for Android?Android WebView?Samsung Internet?Opera Mobile10.1+
The scrollTop
attribute, on getting, must return the result of running these steps:
-
Let document be the element’s node document.
-
If document is not the active document, return zero and terminate these steps.
-
Let window be the value of document’s
defaultView
attribute. -
If window is null, return zero and terminate these steps.
-
If the element is the root element and document is in quirks mode, return zero and terminate these steps.
-
If the element is the root element return the value of
scrollY
on window. -
If the element is the
body
element, document is in quirks mode, and the element is not potentially scrollable, return the value ofscrollY
on window. -
If the element does not have any associated box, return zero and terminate these steps.
-
Return the y-coordinate of the scrolling area at the alignment point with the top of the padding edge of the element.
When setting the scrollTop
attribute these steps must be run:
-
Let y be the given value.
-
Normalize non-finite values for y.
-
Let document be the element’s node document.
-
If document is not the active document, terminate these steps.
-
Let window be the value of document’s
defaultView
attribute. -
If window is null, terminate these steps.
-
If the element is the root element and document is in quirks mode, terminate these steps.
-
If the element is the root element invoke
scroll()
on window withscrollX
on window as first argument and y as second argument, and terminate these steps. -
If the element is the
body
element, document is in quirks mode, and the element is not potentially scrollable, invokescroll()
on window withscrollX
as first argument and y as second argument, and terminate these steps. -
If the element does not have any associated box, the element has no associated scrolling box, or the element has no overflow, terminate these steps.
-
Scroll the element to
scrollLeft
,y, with the scroll behavior being "auto
".
In all current engines.
Opera8+Edge79+
Edge (Legacy)12+IE5+
Firefox for Android?iOS Safari?Chrome for Android?Android WebView?Samsung Internet?Opera Mobile10.1+
The scrollLeft
attribute, on getting, must return the result of running these steps:
-
Let document be the element’s node document.
-
If document is not the active document, return zero and terminate these steps.
-
Let window be the value of document’s
defaultView
attribute. -
If window is null, return zero and terminate these steps.
-
If the element is the root element and document is in quirks mode, return zero and terminate these steps.
-
If the element is the root element return the value of
scrollX
on window. -
If the element is the
body
element, document is in quirks mode, and the element is not potentially scrollable, return the value ofscrollX
on window. -
If the element does not have any associated box, return zero and terminate these steps.
-
Return the x-coordinate of the scrolling area at the alignment point with the left of the padding edge of the element.
When setting the scrollLeft
attribute these steps must be run:
-
Let x be the given value.
-
Normalize non-finite values for x.
-
Let document be the element’s node document.
-
If document is not the active document, terminate these steps.
-
Let window be the value of document’s
defaultView
attribute. -
If window is null, terminate these steps.
-
If the element is the root element and document is in quirks mode, terminate these steps.
-
If the element is the root element invoke
scroll()
on window with x as first argument andscrollY
on window as second argument, and terminate these steps. -
If the element is the
body
element, document is in quirks mode, and the element is not potentially scrollable, invokescroll()
on window with x as first argument andscrollY
on window as second argument, and terminate these steps. -
If the element does not have any associated box, the element has no associated scrolling box, or the element has no overflow, terminate these steps.
-
Scroll the element to x,
scrollTop
, with the scroll behavior being "auto
".
In all current engines.
Opera12.1+Edge79+
Edge (Legacy)12+IE5+
Firefox for Android?iOS Safari?Chrome for Android?Android WebView?Samsung Internet?Opera Mobile12.1+
The scrollWidth
attribute must return the result of running these steps:
-
Let document be the element’s node document.
-
If document is not the active document, return zero and terminate these steps.
-
Let viewport width be the width of the viewport excluding the width of the scroll bar, if any, or zero if there is no viewport.
-
If the element is the root element and document is not in quirks mode return max(viewport scrolling area width, viewport width).
-
If the element is the
body
element, document is in quirks mode and the element is not potentially scrollable, return max(viewport scrolling area width, viewport width). -
If the element does not have any associated box return zero and terminate these steps.
-
Return the width of the element’s scrolling area.
In all current engines.
Opera8+Edge79+
Edge (Legacy)12+IE5+
Firefox for Android?iOS Safari?Chrome for Android?Android WebView?Samsung Internet?Opera Mobile10.1+
The scrollHeight
attribute must return the result of running these steps:
-
Let document be the element’s node document.
-
If document is not the active document, return zero and terminate these steps.
-
Let viewport height be the height of the viewport excluding the height of the scroll bar, if any, or zero if there is no viewport.
-
If the element is the root element and document is not in quirks mode return max(viewport scrolling area height, viewport height).
-
If the element is the
body
element, document is in quirks mode and the element is not potentially scrollable, return max(viewport scrolling area height, viewport height). -
If the element does not have any associated box return zero and terminate these steps.
-
Return the height of the element’s scrolling area.
In all current engines.
Opera8+Edge79+
Edge (Legacy)12+IE5+
Firefox for Android?iOS Safari1+Chrome for Android?Android WebView?Samsung Internet?Opera Mobile10.1+
The clientTop
attribute must run these steps:
-
If the element has no associated box or if the box is inline, return zero.
-
Return the computed value of the border-top-width property plus the height of any scrollbar rendered between the top padding edge and the top border edge, ignoring any transforms that apply to the element and its ancestors.
In all current engines.
Opera8+Edge79+
Edge (Legacy)12+IE5+
Firefox for Android?iOS Safari1+Chrome for Android?Android WebView?Samsung Internet?Opera Mobile10.1+
The clientLeft
attribute must run these steps:
-
If the element has no associated box or if the box is inline, return zero.
-
Return the computed value of the border-left-width property plus the width of any scrollbar rendered between the left padding edge and the left border edge, ignoring any transforms that apply to the element and its ancestors.
In all current engines.
Opera8+Edge79+
Edge (Legacy)12+IE5+
Firefox for Android?iOS Safari1+Chrome for Android?Android WebView?Samsung Internet?Opera Mobile10.1+
The clientWidth
attribute must run these steps:
-
If the element has no associated box or if the box is inline, return zero.
-
If the element is the root element and the element’s node document is not in quirks mode, or if the element is the
body
element and the element’s node document is in quirks mode, return the viewport width excluding the size of a rendered scroll bar (if any). -
Return the width of the padding edge excluding the width of any rendered scrollbar between the padding edge and the border edge, ignoring any transforms that apply to the element and its ancestors.
In all current engines.
Opera8+Edge79+
Edge (Legacy)12+IE5+
Firefox for Android?iOS Safari1+Chrome for Android?Android WebView?Samsung Internet?Opera Mobile10.1+
The clientHeight
attribute must run these steps:
-
If the element has no associated box or if the box is inline, return zero.
-
If the element is the root element and the element’s node document is not in quirks mode, or if the element is the
body
element and the element’s node document is in quirks mode, return the viewport height excluding the size of a rendered scroll bar (if any). -
Return the height of the padding edge excluding the height of any rendered scrollbar between the padding edge and the border edge, ignoring any transforms that apply to the element and its ancestors.
6.1. Element
Scrolling Members
To scroll an element into view element, with a scroll behavior behavior, a block flow direction position block, and an inline base direction position inline, means to run these steps for each ancestor element or viewport that establishes a scrolling box scrolling box, in order of innermost to outermost scrolling box:
-
If the
Document
associated with element is not same origin with theDocument
associated with the element or viewport associated with box, terminate these steps. -
Let element bounding border box be the box that the return value of invoking
getBoundingClientRect()
on element represents. -
Let scrolling box edge A be the beginning edge in the block flow direction of scrolling box, and let element edge A be element bounding border box’s edge on the same physical side as that of scrolling box edge A.
-
Let scrolling box edge B be the ending edge in the block flow direction of scrolling box, and let element edge B be element bounding border box’s edge on the same physical side as that of scrolling box edge B.
-
Let scrolling box edge C be the beginning edge in the inline base direction of scrolling box, and let element edge C be element bounding border box’s edge on the same physical side as that of scrolling box edge C.
-
Let scrolling box edge D be the ending edge in the inline base direction of scrolling box, and let element edge D be element bounding border box’s edge on the same physical side as that of scrolling box edge D.
-
Let element height be the distance between element edge A and element edge B.
-
Let scrolling box height be the distance between scrolling box edge A and scrolling box edge B.
-
Let element width be the distance between element edge C and element edge D.
-
Let scrolling box width be the distance between scrolling box edge C and scrolling box edge D.
-
Let position be the scroll position scrolling box would have by following these steps:
-
If block is "
start
", then align element edge A with scrolling box edge A. -
Otherwise, if block is "
end
", then align element edge B with scrolling box edge B. -
Otherwise, if block is "
center
", then align the center of element bounding border box with the center of scrolling box in scrolling box’s block flow direction. -
Otherwise, block is "
nearest
":- If element edge A and element edge B are both outside scrolling box edge A and scrolling box edge B
- Do nothing.
- If element edge A is outside scrolling box edge A and element height is less than scrolling box height
- If element edge B is outside scrolling box edge B and element height is greater than scrolling box height
- Align element edge A with scrolling box edge A.
- If element edge A is outside scrolling box edge A and element height is greater than scrolling box height
- If element edge B is outside scrolling box edge B and element height is less than scrolling box height
- Align element edge B with scrolling box edge B.
-
If inline is "
start
", then align element edge C with scrolling box edge C. -
Otherwise, if inline is "
end
", then align element edge D with scrolling box edge D. -
Otherwise, if inline is "
center
", then align the center of element bounding border box with the center of scrolling box in scrolling box’s inline base direction. -
Otherwise, inline is "
nearest
":- If element edge C and element edge D are both outside scrolling box edge C and scrolling box edge D
- Do nothing.
- If element edge C is outside scrolling box edge C and element width is less than scrolling box width
- If element edge D is outside scrolling box edge D and element width is greater than scrolling box width
- Align element edge C with scrolling box edge C.
- If element edge C is outside scrolling box edge C and element width is greater than scrolling box width
- If element edge D is outside scrolling box edge D and element width is less than scrolling box width
- Align element edge D with scrolling box edge D.
-
-
If position is the same as scrolling box’s current scroll position, and scrolling box does not have an ongoing smooth scroll, then return.
-
- If scrolling box is associated with an element
- Let associated element be the element.
- If scrolling box is associated with a viewport
- Let document be the viewport’s associated
Document
. Let associated element be document’s root element, if there is one, or null otherwise.
-
Perform a scroll of scrolling box to position, associated element as the associated element and behavior as the scroll behavior.
To scroll an element element to x,y optionally with a scroll behavior behavior (which is "auto
" if omitted) means to:
-
Let box be element’s associated scrolling box.
-
- If box has rightward overflow direction
- Let x be max(0, min(x, element scrolling area width - element padding edge width)).
- If box has leftward overflow direction
- Let x be min(0, max(x, element padding edge width - element scrolling area width)).
-
- If box has downward overflow direction
- Let y be max(0, min(y, element scrolling area height - element padding edge height)).
- If box has upward overflow direction
- Let y be min(0, max(y, element padding edge height - element scrolling area height)).
-
Let position be the scroll position box would have by aligning scrolling area x-coordinate x with the left of box and aligning scrolling area y-coordinate y with the top of box.
-
If position is the same as box’s current scroll position, and box does not have an ongoing smooth scroll, abort these steps.
-
Perform a scroll of box to position, element as the associated element and behavior as the scroll behavior.
7. Extensions to the HTMLElement
Interface
partial interface HTMLElement {readonly attribute Element ?offsetParent ;readonly attribute long offsetTop ;readonly attribute long offsetLeft ;readonly attribute long offsetWidth ;readonly attribute long offsetHeight ; };
In all current engines.
Opera8+Edge79+
Edge (Legacy)12+IE5.5+
Firefox for Android?iOS Safari1+Chrome for Android?Android WebView?Samsung Internet?Opera Mobile10.1+
The offsetParent
attribute must return the result of running these steps:
-
If any of the following holds true return null and terminate this algorithm:
-
The element does not have an associated box.
-
The element is the root element.
-
The element is the
body
element. -
The element’s computed value of the position property is fixed.
-
-
Let ancestor be the parent of the element in the flat tree and repeat these substeps:
-
If ancestor is position property is fixed, terminate this algorithm and return null.
from the element and its computed value of the -
If ancestor is not
from the element and satisfies at least one of the following, terminate this algorithm and return ancestor.-
The element is a containing block of absolutely-positioned descendants (regardless of whether there are any absolutely-positioned descendants).
-
It is the
body
element. -
The computed value of the position property of the element is static and the ancestor is one of the following HTML elements:
td
,th
, ortable
.
-
-
If there is no more parent of ancestor in the flat tree, terminate this algorithm and return null.
-
Let ancestor be the parent of ancestor in the flat tree.
-
In all current engines.
Opera8+Edge79+
Edge (Legacy)12+IE5.5+
Firefox for Android?iOS Safari1+Chrome for Android?Android WebView?Samsung Internet?Opera Mobile10.1+
The offsetTop
attribute must return the result of running these steps:
-
If the element is the
body
element or does not have any associated box return zero and terminate this algorithm. -
If the
offsetParent
of the element is null return the y-coordinate of the top border edge of the first box associated with the element, relative to the initial containing block origin, ignoring any transforms that apply to the element and its ancestors, and terminate this algorithm. -
Return the result of subtracting the y-coordinate of the top padding edge of the first box associated with the
offsetParent
of the element from the y-coordinate of the top border edge of the first box associated with the element, relative to the initial containing block origin, ignoring any transforms that apply to the element and its ancestors.Note: An inline element that consists of multiple line boxes will only have its first box considered.
In all current engines.
Opera8+Edge79+
Edge (Legacy)12+IE5.5+
Firefox for Android?iOS Safari1+Chrome for Android?Android WebView?Samsung Internet?Opera Mobile10.1+
The offsetLeft
attribute must return the result of running these steps:
-
If the element is the
body
element or does not have any associated box return zero and terminate this algorithm. -
If the
offsetParent
of the element is null return the x-coordinate of the left border edge of the first box associated with the element, relative to the initial containing block origin, ignoring any transforms that apply to the element and its ancestors, and terminate this algorithm. -
Return the result of subtracting the x-coordinate of the left padding edge of the first box associated with the
offsetParent
of the element from the x-coordinate of the left border edge of the first box associated with the element, relative to the initial containing block origin, ignoring any transforms that apply to the element and its ancestors.
In all current engines.
Opera8+Edge79+
Edge (Legacy)12+IE5.5+
Firefox for Android?iOS Safari1+Chrome for Android?Android WebView?Samsung Internet?Opera Mobile10.1+
The offsetWidth
attribute must return the result of running these steps:
-
If the element does not have any associated box return zero and terminate this algorithm.
-
Return the width of the axis-aligned bounding box of the border boxes of all fragments generated by the element’s principal box, ignoring any transforms that apply to the element and its ancestors.
If the element’s principal box is an inline-level box which was "split" by a block-level descendant, also include fragments generated by the block-level descendants, unless they are zero width or height.
In all current engines.
Opera8+Edge79+
Edge (Legacy)12+IE5.5+
Firefox for Android?iOS Safari1+Chrome for Android?Android WebView?Samsung Internet?Opera Mobile10.1+
The offsetHeight
attribute must return the result of running these steps:
-
If the element does not have any associated box return zero and terminate this algorithm.
-
Return the height of the axis-aligned bounding box of the border boxes of all fragments generated by the element’s principal box, ignoring any transforms that apply to the element and its ancestors.
If the element’s principal box is an inline-level box which was "split" by a block-level descendant, also include fragments generated by the block-level descendants, unless they are zero width or height.
8. Extensions to the HTMLImageElement
Interface
partial interface HTMLImageElement {readonly attribute long x ;readonly attribute long y ; };
In all current engines.
Opera12.1+Edge79+
Edge (Legacy)12+IENone
Firefox for Android?iOS Safari1+Chrome for Android?Android WebView?Samsung Internet?Opera Mobile12.1+
The x
attribute, on getting, must return the x-coordinate of the left border edge of the
first box associated with the element, relative to the initial containing block origin, ignoring any transforms that apply to the element and its ancestors, or zero if there is no box.
In all current engines.
Opera12.1+Edge79+
Edge (Legacy)12+IENone
Firefox for Android?iOS Safari1+Chrome for Android?Android WebView?Samsung Internet?Opera Mobile12.1+
The y
attribute, on getting, must return the y-coordinate of the top border edge of the
first box associated with the element, relative to the initial containing block origin, ignoring any transforms that apply to the element and its ancestors, or zero if there is no box.
9. Extensions to the Range
Interface
In all current engines.
Opera9+Edge79+
Edge (Legacy)12+IE9+
Firefox for Android?iOS Safari?Chrome for Android?Android WebView?Samsung Internet?Opera Mobile10.1+
partial interface Range {DOMRectList getClientRects (); [NewObject ]DOMRect getBoundingClientRect (); };
In all current engines.
Opera12.1+Edge79+
Edge (Legacy)12+IE9+
Firefox for Android?iOS Safari4+Chrome for Android?Android WebView37+Samsung Internet?Opera Mobile12.1+
The getClientRects()
method, when invoked, must return an empty DOMRectList
object if the range is not in the document and otherwise a DOMRectList
object
containing a list of DOMRect
objects in content order that matches the following constraints:
-
For each element selected by the range, whose parent is not selected by the range, include the border areas returned by invoking
getClientRects()
on the element. -
For each
Text
node selected or partially selected by the range (including when the boundary-points are identical), include aDOMRect
object (for the part that is selected, not the whole line box). The bounds of theseDOMRect
objects are computed using font metrics; thus, for horizontal writing, the vertical dimension of each box is determined by the font ascent and descent, and the horizontal dimension by the text advance width. If the range covers a partial typographic character unit (e.g. half a surrogate pair or part of a grapheme cluster), the full typographic character unit must be included for the purpose of computing the bounds of the relevantDOMRect
. [CSS-TEXT-3] The transforms that apply to the ancestors are applied.
Note: The DOMRect
objects returned by getClientRects()
are not live.
In all current engines.
Opera12.1+Edge79+
Edge (Legacy)12+IE9+
Firefox for Android?iOS Safari4+Chrome for Android?Android WebView37+Samsung Internet?Opera Mobile12.1+
The getBoundingClientRect()
method, when invoked, must return the result of the following
algorithm:
-
Let list be the result of invoking
getClientRects()
on the same range this method was invoked on. -
If list is empty return a
DOMRect
object whosex
,y
,width
andheight
members are zero. -
If all rectangles in list have zero width or height, return the first rectangle in list.
-
Otherwise, return a
DOMRect
object describing the smallest rectangle that includes all of the rectangles in list of which the height or width is not zero.
Note: The DOMRect
object returned by getBoundingClientRect()
is not live.
10. Extensions to the MouseEvent
Interface
In all current engines.
Opera10.6+Edge79+
Edge (Legacy)12+IE9+
Firefox for Android?iOS Safari?Chrome for Android?Android WebView?Samsung Internet?Opera Mobile11+
The object IDL fragment redefines some members. Can we resolve this somehow?
partial interface MouseEvent {readonly attribute double screenX ;readonly attribute double screenY ;readonly attribute double pageX ;readonly attribute double pageY ;readonly attribute double clientX ;readonly attribute double clientY ;readonly attribute double x ;readonly attribute double y ;readonly attribute double offsetX ;readonly attribute double offsetY ; };partial dictionary MouseEventInit {double = 0.0;
screenX double = 0.0;
screenY double = 0.0;
clientX double = 0.0; };
clientY
The screenX
attribute must return the x-coordinate of
the position where the event occurred relative to the origin of the Web-exposed screen area.
The screenY
attribute must return the y-coordinate of
the position where the event occurred relative to the origin of the Web-exposed screen area.
In all current engines.
Opera12.1+Edge79+
Edge (Legacy)12+IE9+
Firefox for Android?iOS Safari?Chrome for Android?Android WebView37+Samsung Internet?Opera Mobile12.1+
The pageX
attribute must follow these steps:
-
If the event’s dispatch flag is set, return the horizontal coordinate of the position where the event occurred relative to the origin of the initial containing block and terminate these steps.
-
Let offset be the value of the
scrollX
attribute of the event’s associatedWindow
object, if there is one, or zero otherwise. -
Return the sum of offset and the value of the event’s
clientX
attribute.
In all current engines.
Opera12.1+Edge79+
Edge (Legacy)12+IE9+
Firefox for Android?iOS Safari?Chrome for Android?Android WebView37+Samsung Internet?Opera Mobile12.1+
The pageY
attribute must follow these steps:
-
If the event’s dispatch flag is set, return the vertical coordinate of the position where the event occurred relative to the origin of the initial containing block and terminate these steps.
-
Let offset be the value of the
scrollY
attribute of the event’s associatedWindow
object, if there is one, or zero otherwise. -
Return the sum of offset and the value of the event’s
clientY
attribute.
The clientX
attribute must return the x-coordinate of
the position where the event occurred relative to the origin of the viewport.
The clientY
attribute must return the y-coordinate of
the position where the event occurred relative to the origin of the viewport.
In all current engines.
Opera12.1+Edge79+
Edge (Legacy)12+IE9+
Firefox for Android?iOS Safari?Chrome for Android?Android WebView37+Samsung Internet?Opera Mobile12.1+
The x
attribute must return the value of clientX
.
In all current engines.
Opera12.1+Edge79+
Edge (Legacy)12+IE9+
Firefox for Android?iOS Safari?Chrome for Android?Android WebView37+Samsung Internet?Opera Mobile12.1+
The y
attribute must return the value of clientY
.
In all current engines.
Opera12.1+Edge79+
Edge (Legacy)12+IE9+
Firefox for Android43+iOS Safari?Chrome for Android?Android WebView37+Samsung Internet?Opera Mobile12.1+
The offsetX
attribute must follow these steps:
-
If the event’s dispatch flag is set, return the x-coordinate of the position where the event occurred relative to the origin of the padding edge of the target node, ignoring the transforms that apply to the element and its ancestors, and terminate these steps.
-
Return the value of the event’s
pageX
attribute.
In all current engines.
Opera12.1+Edge79+
Edge (Legacy)12+IE9+
Firefox for Android43+iOS Safari?Chrome for Android?Android WebView37+Samsung Internet?Opera Mobile12.1+
The offsetY
attribute must follow these steps:
-
If the event’s dispatch flag is set, return the y-coordinate of the position where the event occurred relative to the origin of the padding edge of the target node, ignoring the transforms that apply to the element and its ancestors, and terminate these steps.
-
Return the value of the event’s
pageY
attribute.
11. Geometry
11.1. The GeometryUtils
Interface
enum {
CSSBoxType ,
"margin" ,
"border" ,
"padding" };
"content" dictionary {
BoxQuadOptions CSSBoxType = "border";
box GeometryNode ; // XXX default document (i.e. viewport) };
relativeTo dictionary {
ConvertCoordinateOptions CSSBoxType = "border";
fromBox CSSBoxType = "border"; };
toBox interface mixin {
GeometryUtils sequence <DOMQuad >getBoxQuads (optional BoxQuadOptions = {});
options DOMQuad convertQuadFromNode (DOMQuadInit ,
quad GeometryNode ,
from optional ConvertCoordinateOptions = {});
options DOMQuad convertRectFromNode (DOMRectReadOnly ,
rect GeometryNode ,
from optional ConvertCoordinateOptions = {});
options DOMPoint convertPointFromNode (DOMPointInit ,
point GeometryNode ,
from optional ConvertCoordinateOptions = {}); // XXX z,w turns into 0 };
options Text includes GeometryUtils ; // like RangeElement includes GeometryUtils ;CSSPseudoElement includes GeometryUtils ;Document includes GeometryUtils ;typedef (Text or Element or CSSPseudoElement or Document );
GeometryNode
The getBoxQuads(options)
method must run the following steps:
-
DOM order
p1 = top left even in RTL
scale to 0 means divide by zero, return 0x0
cross-frames not allowed, throw WrongDocumentError?
points are flattened (3d transform), z=0. like getClientRect
test block in inline
pseudo-elements before/after are children of the element
viewport boxes are all the same
The convertQuadFromNode(quad, from, options)
method
must run the following steps:
The convertRectFromNode(rect, from, options)
method
must run the following steps:
The convertPointFromNode(point, from, options)
method must run the following steps:
12. VisualViewport
12.1. The VisualViewport
Interface
In all current engines.
Opera?Edge79+
Edge (Legacy)?IENone
Firefox for Android68+iOS Safari?Chrome for Android?Android WebView?Samsung Internet?Opera Mobile?
[Exposed =Window ]interface :
VisualViewport EventTarget {readonly attribute double offsetLeft ;readonly attribute double offsetTop ;readonly attribute double pageLeft ;readonly attribute double pageTop ;readonly attribute double width ;readonly attribute double height ;readonly attribute double scale ;attribute EventHandler onresize ;attribute EventHandler onscroll ; };
In all current engines.
Opera?Edge79+
Edge (Legacy)?IENone
Firefox for Android68+iOS Safari?Chrome for Android?Android WebView?Samsung Internet?Opera Mobile?
The offsetLeft
attribute must run these steps:
-
If the visual viewport’s associated document is not fully active, return 0.
-
Otherwise, return the offset of the left edge of the visual viewport from the left edge of the layout viewport.
In all current engines.
Opera?Edge79+
Edge (Legacy)?IENone
Firefox for Android68+iOS Safari?Chrome for Android?Android WebView?Samsung Internet?Opera Mobile?
The offsetTop
attribute must run these steps:
-
If the visual viewport’s associated document is not fully active, return 0.
-
Otherwise, return the offset of the top edge of the visual viewport from the top edge of the layout viewport.
In all current engines.
Opera?Edge79+
Edge (Legacy)?IENone
Firefox for Android68+iOS Safari?Chrome for Android?Android WebView?Samsung Internet?Opera Mobile?
The pageLeft
attribute must run these steps:
-
If the visual viewport’s associated document is not fully active, return 0.
-
Otherwise, return the offset of the left edge of the visual viewport from the left edge of the initial containing block of the layout viewport’s document.
In all current engines.
Opera?Edge79+
Edge (Legacy)?IENone
Firefox for Android68+iOS Safari?Chrome for Android?Android WebView?Samsung Internet?Opera Mobile?
The pageTop
attribute must run these steps:
-
If the visual viewport’s associated document is not fully active, return 0.
-
Otherwise, return the offset of the top edge of the visual viewport from the top edge of the initial containing block of the layout viewport’s document.
In all current engines.
Opera?Edge79+
Edge (Legacy)?IENone
Firefox for Android68+iOS Safari?Chrome for Android?Android WebView?Samsung Internet?Opera Mobile?
The width
attribute must run these steps:
-
If the visual viewport’s associated document is not fully active, return 0.
-
Otherwise, return the width of the visual viewport excluding the width of any rendered vertical classic scrollbar that is fixed to the visual viewport.
Note: Since this value is returned in CSS pixels, the value will decrease in magnitude if either page zoom or the scale factor is increased.
Note: A scrollbar that is fixed to the visual viewport is one that does not change size or location as the visual viewport is zoomed and panned. Because this value is in CSS pixels, when excluding the scrollbar width the UA must account for how large the scrollbar is as measured in CSS pixels. That is, the amount excluded decreases when zooming in and increases when zooming out.
In all current engines.
Opera?Edge79+
Edge (Legacy)?IENone
Firefox for Android68+iOS Safari?Chrome for Android?Android WebView?Samsung Internet?Opera Mobile?
The height
attribute must run these steps:
-
If the visual viewport’s associated document is not fully active, return 0.
-
Otherwise, return the height of the visual viewport excluding the height of any rendered horizontal classic scrollbar that is fixed to the visual viewport.
In all current engines.
Opera?Edge79+
Edge (Legacy)?IENone
Firefox for Android68+iOS Safari?Chrome for Android?Android WebView?Samsung Internet?Opera Mobile?
The scale
attribute must run these steps:
-
If the visual viewport’s associated document is not fully active, return 0 and abort these steps.
-
If there is no output device, return 1 and abort these steps.
-
Otherwise, return the visual viewport’s scale factor.
onresize
is the event handler IDL attribute for the resize event.
onscroll
is the event handler IDL attribute for the scroll event.
13. Events
13.1. Resizing viewports
In all current engines.
Opera7+Edge79+
Edge (Legacy)12+IE4+
Firefox for Android?iOS Safari?Chrome for Android?Android WebView1+Samsung Internet?Opera Mobile10.1+
This section integrates with the event loop defined in HTML. [HTML]
When asked to run the resize steps for a Document
doc, run these steps:
-
If doc’s viewport has had its width or height changed (e.g. as a result of the user resizing the browser window, or changing page zoom, or an
iframe
element’s dimensions are changed) since the last time these steps were run, fire an event named resize at theWindow
object associated with doc. -
If the
VisualViewport
associated with doc has had its scale, width, or height properties changed since the last time these steps were run, fire an event named resize at theVisualViewport
.
13.2. Scrolling
This section integrates with the event loop defined in HTML. [HTML]
Each Document
has an associated list of pending scroll event targets, initially empty.
Each Document
has an associated list of pending scrollend event targets, initially empty.
Whenever a viewport gets scrolled (whether in response to user interaction or by an API), the user agent must run these steps:
-
Let doc be the viewport’s associated
Document
. -
If doc is already in doc’s pending scroll event targets, abort these steps.
-
Append doc to doc’s pending scroll event targets.
Whenever an element gets scrolled (whether in response to user interaction or by an API), the user agent must run these steps:
-
Let doc be the element’s node document.
-
If the element is already in doc’s pending scroll event targets, abort these steps.
-
Append the element to doc’s pending scroll event targets.
When asked to run the scroll steps for a Document
doc, run these steps:
-
For each item target in doc’s pending scroll event targets, in the order they were added to the list, run these substeps:
-
If target is a
Document
, fire an event named scroll that bubbles at target and fire an event named scroll at theVisualViewport
that is associated with target. -
Otherwise, fire an event named scroll at target.
-
-
Empty doc’s pending scroll event targets.
Whenever scrolling is completed, the user agent must run these steps:
-
If scrolling was done on a viewport, let doc be the viewport’s associated
Document
and target be the viewport. Otherwise, scrolling is done on an element and let doc be the element’s node document and target be the element. -
If target is already in doc’s pending scrollend event targets, abort these steps.
-
Append target to doc’s pending scrollend event targets.
-
For each item target in doc’s pending scrollend event targets, in the order they were added to the list, run these substeps:
-
If target is a
Document
, fire an event named scrollend that bubbles at target. -
Otherwise, fire an event named scrollend at target.
-
-
Empty doc’s pending scrollend event targets.
13.3. Event summary
This section is non-normative.
Event | Interface | Interesting targets | Description |
---|---|---|---|
In all current engines.
Firefox91+Safari13+Chrome62+
Opera?Edge79+ Edge (Legacy)NoneIENone Firefox for Android68+iOS Safari?Chrome for Android?Android WebView?Samsung Internet8.0+Opera Mobile? resize
| Event
| Window , VisualViewport
| Fired at the Window when the viewport is resized. Fired at VisualViewport when the visual viewport is resized
or the layout viewport is scaled.
|
In all current engines.
Firefox6+Safari2+Chrome1+
Opera11.6+Edge79+ Edge (Legacy)12+IE9+ Firefox for Android?iOS Safari?Chrome for Android?Android WebView?Samsung Internet?Opera Mobile12+ In all current engines.
Firefox6+Safari1.3+Chrome1+
Opera12.1+Edge79+ Edge (Legacy)12+IE9+ Firefox for Android?iOS Safari?Chrome for Android?Android WebView?Samsung Internet?Opera Mobile12.1+ In all current engines.
Firefox91+Safari13+Chrome62+
Opera?Edge79+ Edge (Legacy)NoneIENone Firefox for Android68+iOS Safari?Chrome for Android?Android WebView?Samsung Internet8.0+Opera Mobile? scroll
| Event
| Document , elements, VisualViewport
| Fired at the Document or element when the viewport or element is scrolled, respectively. Fired at the VisualViewport when the visual viewport is scrolled.
|
scrollend
| Event
| Document , elements
| Fired at the Document or element when scroll is completed: the viewport or element has been scrolled, the scroll sequence has ended and any scroll offset changes have been applied.
|
14. Security and Privacy Considerations
The Screen
interface exposes information about the user’s display configuration, which maybe be used as input to fingerprinting algorithms. User agents may choose to hide or quantize information about the screen size or configuration, in order to protect the user’s privacy.
MouseEvent
contains information about the screen-relative coordinates of the event. User agents may set these properties to values that obscure the actual screen-relative location of the event, in order to protect the user’s privacy.
15. Changes
This section documents some of the changes between publications of this specification. This section is not exhaustive. Bug fixes and editorial changes are generally not listed.
Changes From 07 July 2022
-
Introduced the
VisualViewport
API and related concepts -
Pinch zoom is now renamed to scale factor
Changes From 22 June 2022
-
Adam Argyle moved the scrollend event from WICG overscroll-scrollend-events to [CSSOM-VIEW-1]
Changes From 19 October 2020
-
Added the "Security and Privacy Considerations" section
-
Fixed a logical error in the Terminology section.
-
Moved the scroll-behavior property to [CSS-OVERFLOW-3]
Changes From 31 January 2020
-
Added Simon Fraser as editor
-
Renamed the arguments to
resizeTo()
to be width and height (4727)
Changes From 17 December 2013 To 31 January 2020
-
The
scrollIntoView()
method onElement
was changed and extended. -
The
scrollTop
andscrollLeft
IDL attributes onElement
changed to no longer take an object; thescroll()
,scrollTo()
andscrollBy()
methods were added instead. -
The
scrollWidth
,scrollHeight
,clientTop
,clientLeft
,clientWidth
andclientHeight
IDL attributes onElement
were changed back to return integers. -
The
DOMRectList
interface was removed. -
The
scrollingElement
IDL attribute onDocument
was added. -
Some readonly attributes on
Window
were annotated with[Replaceable]
IDL extended attribute. -
MediaQueryList
, scroll event and resize event are integrated with the event loop in HTML so they are synchronized with animation frames. -
The
instant
value of scroll-behavior was renamed to auto. -
The origin of
scrollLeft
onElement
was changed (for RTL). -
The
scrollIntoView()
method onElement
andscroll()
,scrollTo()
andscrollBy()
methods onWindow
take the relevant dictionary as the first argument. -
The
MediaQueryList
interface was changed to use regular event API and defineaddListener()
in terms of that.
Changes From 4 August 2011 To 17 December 2013
-
The specification now handles right-to-left and vertical writing modes.
-
The specification is now aware of page zoom and pinch zoom.
-
The scroll-behavior CSS property is introduced and scrolling APIs are extended with a mechanism to control smooth scrolling.
-
The
moveTo()
,moveBy()
,resizeTo()
andresizeBy()
methods are now defined. -
innerWidth
et al now use the WebIDL typedouble
instead oflong
. -
devicePixelRatio
is now defined. -
The
features
argument to window.open() is now defined. -
The
colorDepth
andpixelDepth
attributes ofScreen
now always return 24. -
The
elementsFromPoint()
method ofElement
is introduced. -
The specification is now aware of transforms.
-
Some geometry utility APIs are introduced but are not yet specified.
-
ClientRect
has been renamed toDOMRect
and has moved to the Geometry specification. [GEOMETRY-1] -
The specification now defines when the
resize
andscroll
events fire.
16. Acknowledgements
The editors would like to thank Alan Stearns, Alexey Feldgendler, Antonio Gomes, Björn Höhrmann, Boris Zbarsky, Chris Rebert, Corey Farwell, Dan Bates, David Vest, Elliott Sprehn, Garrett Smith, Henrik Andersson, Hallvord R. M. Steen, Kang-Hao Lu, Koji Ishii, Leif Arne Storset, Luiz Agostini, Maciej Stachowiak, Michael Dyck, Mike Wilson, Morten Stenshorne, Olli Pettay, Pavel Curtis, Peter-Paul Koch, Rachel Kmetz, Rick Byers, Robert O’Callahan, Sam Weinig, Scott Johnson, Sebastian Zartner, Stewart Brodie, Sylvain Galineau, Tab Atkins, Tarquin Wilton-Jones, Thomas Moore, Thomas Shinnick, and Xiaomei Ji for their contributions to this document.
Special thanks to the Microsoft employees who first implemented many of the features specified in this draft, which were first widely deployed by the Windows Internet Explorer browser.