GeezerVisonThe World Wide Web, restored to 800 pixels of glory. | |||||||||||||||||||||||||||||||||||||||||||
| Home|About|Gaming cabinet|Archives|How it works|Starter sites | |||||||||||||||||||||||||||||||||||||||||||
GeezerVison is showing drafts.csswg.org — CSSOM View Module Level 1 1. BackgroundMany 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. TerminologyTerminology used in this specification is from DOM, CSSOM and HTML. [DOM] [CSSOM] [HTML] An element body (which will be the
Note: A 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 Alignment Overflow and Scroll Containers. 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.
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:
The ending edges of a particular set of edges of a box or element are the following edges:
The 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 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 pixelsAll 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. 2.2. ZoomingThere 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 informationUser 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 must return the result of the following algorithm:
The Web-exposed available screen area must return the result of the following algorithm:
3. Common InfrastructureThis specification depends on the WHATWG Infra standard. [INFRA] 3.1. ScrollingA non-interrupted scroll result is a An interrupted scroll result is a When a user agent is to perform a scroll of a scrolling box box,
to a given position position,
an associated element or pseudo-element element and optionally a scroll behavior behavior
(which is "
Note: 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 occurred. When a user agent is to perform a scroll of a viewport to a given position position and optionally a scroll behavior behavior
(which is "
Note: Conceptually, the visual viewport is scrolled until it "bumps up" against the layout viewport edge and then "pushes" the layout viewport by applying the scroll delta to the layout viewport. However, the scrolls in the steps above are computed ahead of time and applied in the opposite order so that the layout viewport is scrolled before the visual viewport. This is done for historical reasons to ensure consistent scroll event ordering. See the example for a visual depiction.
The user pinch-zooms into the document and ticks their mouse wheel, requesting the user agent scroll the document down by 50px. Because the document
is pinch-zoomed in, the visual viewport has 20px of room to scroll. The user agent distributes the scroll by scrolling the visual viewport down by
20px and the layout viewport by 30px.
The user is viewing a document in a mobile user agent. The document focuses an offscreen text input element, showing a virtual keyboard which shrinks
the visual viewport. The user agent must now bring the element into view in the visual viewport. The user agent scrolls the layout viewport so that
the element is visible within it, then the visual viewport so that the element is visible to the user.
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:
Note: This algorithm is used when navigating to the Tests
3.2. WebIDL valuesWhen asked to normalize non-finite values for a value x,
if x is one of the three special floating point literal values
( 4. Extensions to the
|
| Event handler | Event handler event type |
|---|---|
onchange
| change |
[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 ; };
The media attribute must return the value it was initialized to.
The matches attribute must return the value it was initialized to.
This section is non-normative.
| Event | Interface | Interesting targets | Description |
|---|---|---|---|
change
| MediaQueryListEvent
| MediaQueryList
| Fired at the MediaQueryList when the matches state changes.
|
Screen InterfaceAs 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 ; };
The availWidth attribute must return the width of the Web-exposed
available screen area.
The availHeight attribute must return the height of the
Web-exposed available screen area.
The width attribute must return the width of the Web-exposed
screen area.
The height attribute must return the height of the Web-exposed
screen area.
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.
Document Interfacepartial interface Document {Element ?elementFromPoint (double ,x double );y sequence <Element >elementsFromPoint (double ,x double );y CaretPosition ?caretPositionFromPoint (double ,x double ,y optional CaretPositionFromPointOptions = {});options readonly attribute Element ?scrollingElement ; };dictionary {CaretPositionFromPointOptions sequence <ShadowRoot >= []; };shadowRoots
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.
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.
The caretPositionFromPoint(x, y, options) 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:
Otherwise:
Let caretPosition be a tuple consisting of a caretPositionNode (a node) and a caretPositionOffset (a non-negative integer) 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.
Let startNode be the caretPositionNode of the caretPosition, and let startOffset be the caretPositionOffset of the caretPosition.
While startNode is a node, startNode’s root is a shadow root, and startNode’s root is not a shadow-including inclusive ancestor of any of options["shadowRoots"], repeat these steps:
Return a caret position with its properties set as follows:
caret node is set to startNode.
caret offset is set to startOffset.
Note: This caret position is not live.
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.
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 in either axis, return the body 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.
CaretPosition InterfaceA caret position gives the position of a text insertion point indicator. It always has an associated
caret node and caret offset. 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 node is a text entry widget that is a replaced element,
and that is in the document,
return a scaled 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.
Otherwise:
Let caretRange be a collapsed Range object whose start node and end node are set to caret node, and whose start offset and end offset are set to caret offset.
Return the DOMRect object which is the result of invoking the getBoundingClientRect() method on caretRange.
Note: This DOMRect object is not live.
Element Interfaceenum {ScrollLogicalPosition ,"start" ,"center" ,"end" };"nearest" dictionary :ScrollIntoViewOptions ScrollOptions {ScrollLogicalPosition = "start";block ScrollLogicalPosition = "nearest";inline ScrollIntoViewContainer = "all"; };container enum {ScrollIntoViewContainer ,"all" };"nearest" dictionary {CheckVisibilityOptions boolean =checkOpacity false ;boolean =checkVisibilityCSS false ;boolean =contentVisibilityAuto false ;boolean =opacityProperty false ;boolean =visibilityProperty false ; };partial interface Element {DOMRectList getClientRects (); [NewObject ]DOMRect getBoundingClientRect ();boolean checkVisibility (optional CheckVisibilityOptions = {});options Promise <ScrollResult >scrollIntoView (optional (boolean or ScrollIntoViewOptions )= {});arg Promise <ScrollResult >scroll (optional ScrollToOptions = {});options Promise <ScrollResult >scroll (unrestricted double ,x unrestricted double );y Promise <ScrollResult >scrollTo (optional ScrollToOptions = {});options Promise <ScrollResult >scrollTo (unrestricted double ,x unrestricted double );y Promise <ScrollResult >scrollBy (optional ScrollToOptions = {});options Promise <ScrollResult >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 ;readonly attribute double currentCSSZoom ; };
Note: The checkOpacity and checkVisibilityCSS properties are historical names.
These properties have aliases that match the new naming scheme,
namely opacityProperty and visibilityProperty.
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 scaled DOMRectList object containing a single DOMRect 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 containing DOMRect 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.
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 whose x,
y, width and height 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 an ancestor of this in the flat tree has content-visibility: hidden, return false.
If either the opacityProperty
or the checkOpacity
dictionary members of options
are true,
and this, or an ancestor of this in the flat tree,
has a computed opacity value of 0,
return false.
If either the visibilityProperty
or the checkVisibilityCSS
dictionary members of options
are true,
and this is invisible,
return false.
If the contentVisibilityAuto dictionary member of options
is true
and an ancestor of this in the flat tree
skips its contents
due to content-visibility: auto,
return false.
Return true.
The scrollIntoView(arg) method must run these steps:
Let behavior be "auto".
Let block be "start".
Let inline be "nearest".
Let container be null.
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 a promise resolved with a non-interrupted scroll result and abort the remaining steps.
Scroll the element into view
with behavior, block, inline, and container.
Let scrollPromise be the Promise returned from this step
Optionally perform some other action that brings the element to the user’s attention.
Return scrollPromise.
< style >
. scroller { overflow : auto ; scroll-padding : 8 px ; }
. slide { scroll-margin : 16 px ; scroll-snap-align : center ; }
</ style >
< div class = "carousel" >
< div class = "slides scroller" >
< div id = "s1" class = "slide" >
< div id = "s2" class = "slide" >
< div id = "s3" class = "slide" >
</ div >
< div class = "markers" >
< button data-target = "s1" > 1</ button >
< button data-target = "s2" > 2</ button >
< button data-target = "s3" > 3</ button >
</ div >
</ div >
< script >
document. querySelector( '.markers' ). addEventListener( 'click' , ( evt) => {
const target = document. getElementById( evt. target. dataset. target);
if ( ! target) return ;
// scrollIntoView correctly aligns target item respecting scroll-snap-align,
// scroll-margin, and the scroll container's scroll-padding.
target. scrollIntoView({
// Only scroll the nearest scroll container.
container: 'nearest' ,
behavior: 'smooth'
});
});
</ script >
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 and top 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, return a promise resolved with a non-interrupted scroll result and abort the remaining steps.
Let window be the value of document’s defaultView attribute.
If window is null, return a promise resolved with a non-interrupted scroll result and abort the remaining steps.
If the element is the root element and document is in quirks mode, return a promise resolved with a non-interrupted scroll result and abort the remaining steps.
If the element is the root element, return the Promise returned by scroll() on window after the method is invoked with
scrollX on window as first argument and y as second argument, and abort the remaining steps.
If the element is the body element,
document is in quirks mode,
and the element is not potentially scrollable in either axis,
return the Promise returned by scroll() on window after the method is invoked with
options as the only argument, and abort the remaining steps.
If the element does not have any associated box, the element has no associated scrolling box, or the element has no overflow, return a promise resolved with a non-interrupted scroll result and abort the remaining steps.
Scroll the element to x,y,
with the scroll behavior being the value of the behavior dictionary member of options. Let scrollPromise be the Promise returned from this step.
Return scrollPromise.
When the scrollTo() method is invoked, the
user agent must act as if the scroll() method was invoked with the same arguments.
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 and top 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 the left dictionary member.
Return the Promise returned by scroll() after the method is invoked with options as the only argument.
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 in at least one axis, return the value of scrollY 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 with scrollX 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 in at least one axis, invoke scroll() on window with scrollX 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".
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 in at least one axis, return the value of scrollX 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 and scrollY 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 in at least one axis, invoke scroll() on window with x as first argument and scrollY 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".
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 in the x axis, 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.
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 in the y axis, 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.
The clientTop attribute must run these steps:
If the element has no associated box or if the box is inline, return zero.
Return the unscaled 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.
The clientLeft attribute must run these steps:
If the element has no associated box or if the box is inline, return zero.
Return the unscaled 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.
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 unscaled width of the padding edge excluding the width of any rendered scrollbar between the padding edge and the border edge, ignoring any transforms or that apply to the element and its ancestors.
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 unscaled 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.
The currentCSSZoom attribute must return the
effective zoom of the element, or 1.0 if the element isn’t being rendered.
Element Scrolling MembersTo determine the scroll-into-view position of a target, which is an Element, pseudo-element, or Range, with a scroll behavior behavior, a block flow direction position block, an inline base direction position inline, and a scrolling box scrolling box, run the following steps:
Let target bounding border box be the box represented by the return value of invoking Element’s getBoundingClientRect(), if target is an Element, or Range’s getBoundingClientRect(), if target is a Range.
Let scrolling box edge A be the beginning edge in the block flow direction of scrolling box, and let element edge A be target 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 target 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 target 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 target 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 target bounding border box with the center of scrolling box in scrolling box’s block flow direction.
Otherwise, block is "nearest":
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 target bounding border box with the center of scrolling box in scrolling box’s inline base direction.
Otherwise, inline is "nearest":
If target is an Element, and the target element defines some scroll snap positions, then the user agent must scroll snap the resulting position to one of that element’s scroll snap positions if its nearest scroll container is a scroll snap container. The user agent may also do this even when the scroll container has scroll-snap-type: none.
Return position.
Let ancestorPromises be an empty set of Promises.
For each ancestor element or viewport that establishes a scrolling box scrolling box, in order of innermost to outermost scrolling box, run these substeps:
If the Document associated with target is not same origin with the Document associated with the element or viewport associated with scrolling box,
abort any remaining iteration of this loop.
Let position be the scroll position resulting from running the steps to determine the scroll-into-view position of target with behavior as the scroll behavior, block as the block flow position, inline as the inline base direction position and scrolling box as the scrolling box.
If position is not the same as scrolling box’s current scroll position, or scrolling box has an ongoing smooth scroll,
Promise retured from this step to the set ancestorPromises.
Let document be the viewport’s associated Document.
Let root element be document’s root element, if there is one, or null otherwise.
Perform a scroll of the viewport to position, with root element as the associated element and behavior
as the scroll behavior.
Add the Promise retured from this step in the set ancestorPromises.
If container is not null and either scrolling box is a shadow-including inclusive ancestor of container or is a viewport whose document is a shadow-including inclusive ancestor of container, abort any remaining iteration of this loop.
Let scrollPromise be a new Promise.
Return scrollPromise, and run the remaining steps in parallel.
Wait until all Promises in ancestorPromises have settled.
If all Promises in ancestorPromises were resolved with a non-interrupted scroll result,
resolve scrollPromise with a non-interrupted scroll result.
Otherwise, resolve scrollPromise with an interrupted scroll result.
To scroll an element (or pseudo-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.
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, return a promise resolved with a non-interrupted scroll result and abort the remaining steps.
Perform a scroll of box to position, element as the associated element and behavior as the scroll behavior.
Let scrollPromise be the Promise returned from this step.
Return scrollPromise.
HTMLElement Interfacepartial interface HTMLElement {readonly attribute Element ?scrollParent ;readonly attribute Element ?offsetParent ;readonly attribute long offsetTop ;readonly attribute long offsetLeft ;readonly attribute long offsetWidth ;readonly attribute long offsetHeight ; };
The scrollParent 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 and no ancestor establishes a fixed position containing block.
Let ancestor be the containing block of the element in the flat tree and repeat these substeps:
If ancestor is the initial containing block, return the scrollingElement for the element’s document if it is not closed-shadow-hidden from the element, otherwise return null.
If ancestor is not closed-shadow-hidden from the element, and is a scroll container, terminate this algorithm and return ancestor.
If the computed value of the position property of ancestor is fixed, and no ancestor establishes a fixed position containing block, terminate this algorithm and return null.
Let ancestor be the containing block of ancestor in the flat tree.
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 and no ancestor establishes a fixed position containing block.
Let ancestor be the parent of the element in the flat tree and repeat these substeps:
If ancestor is closed-shadow-hidden from the element, its computed value of the position property is fixed, and no ancestor establishes a fixed position containing block, terminate this algorithm and return null.
If ancestor is not closed-shadow-hidden from the element and satisfies at least one of the following, terminate this algorithm and return ancestor.
The element is in a fixed position containing block, and ancestor is a containing block for fixed-positioned descendants.
The element is not in a fixed position containing block, and:
ancestor 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, or table.
The element has a different effective zoom than ancestor.
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.
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 unscaled y-coordinate of the top border edge of the first box associated with the element, relative to the initial containing block origin, ignoring any transformsthat apply to the element and its ancestors and terminate this algorithm.
Return the unscaled 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.
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 unscaled 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 unscaled 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.
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 unscaled 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.
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 unscaled 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.
HTMLImageElement Interfacepartial interface HTMLImageElement {readonly attribute long x ;readonly attribute long y ; };
The x attribute, on getting, must return the scaled 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.
The y attribute, on getting, must return the scaled 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.
Range Interfacepartial interface Range {DOMRectList getClientRects (); [NewObject ]DOMRect getBoundingClientRect (); };
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 scaled DOMRect object (for the part that is selected, not
the whole line box). The bounds of these DOMRect 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 relevant DOMRect. [CSS-TEXT-3] The
transforms that apply to the ancestors are applied.
Note: The DOMRect objects returned by getClientRects() are not live.
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 whose x, y, width and height 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.
MouseEvent InterfaceThe 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.
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 associated Window object, if there is one, or zero otherwise.
Return the sum of offset and the value of the event’s clientX attribute.
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 associated Window 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.
The x attribute must return the value of clientX.
The y attribute must return the value of clientY.
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.
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.
GeometryUtils Interfaceenum {CSSBoxType ,"margin" ,"border" ,"padding" };"content" dictionary {BoxQuadOptions CSSBoxType = "border";box GeometryNode ; };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 = {}); };options Text includes GeometryUtils ; // like RangeElement includes GeometryUtils ;CSSPseudoElement includes GeometryUtils ;Document includes GeometryUtils ;typedef (Text or Element or CSSPseudoElement or Document );GeometryNode
The GeometryUtils methods operate on a node’s local box geometry.
The getBoxQuads() method returns one DOMQuad per relevant
box fragment, in flat tree order.
Unless relativeTo is specified,
the returned coordinates are expressed relative to the layout viewport.
For the purpose of the GeometryUtils methods, the associated document
of a Document is itself, the associated document of a CSSPseudoElement is
its element’s node document, and the associated document
of any other GeometryNode is its node document.
To check the documents for coordinate conversion given two
GeometryNodes node and from:
Let nodeDocuments be a list containing node’s associated document. While the last document in nodeDocuments has a container document, append that container document to nodeDocuments.
Let fromDocuments be a list constructed in the same way for from.
Let documents contain the shortest prefixes of nodeDocuments and fromDocuments that end with a document common to both lists. If there is no such document, let documents contain only the first item of each list.
If any document in documents is not same origin with the
associated document of node, then throw a
SecurityError.
For a CSSPseudoElement,
the GeometryUtils methods operate on the boxes generated by the pseudo-element itself.
This includes the boxes of generated content pseudo-elements such as ::before and ::after,
including when those boxes are out-of-flow, for example due to absolute positioning.
If the CSSPseudoElement is a sub-pseudo-element,
the methods operate on the sub-pseudo-element’s own boxes and fragments.
If the pseudo-element generates no boxes,
getBoxQuads() returns an empty list.
GeometryNode node
relative to a GeometryNode ancestor,
run the following steps:
Let current be node.
Let transformationMatrix be a new DOMMatrix.
While current is not null:
If current is ancestor, return transformationMatrix.
Let nextAncestor be null.
If current is an Element, then:
Let currentTransformationMatrix be a new DOMMatrix
representing the current transformation matrix of current. [CSS-TRANSFORMS-1]
Set transformationMatrix to the result of multiplying currentTransformationMatrix by transformationMatrix.
If there is an element that establishes the containing block of current, let nextAncestor be that element. Otherwise, let nextAncestor be current’s node document.
If nextAncestor is a Document,
let offsetX be the horizontal offset and offsetY
be the vertical offset from the border edge of current
to the origin of the initial containing block,
ignoring any transforms that apply to current and its ancestors.
Otherwise, let offsetX be the horizontal offset and offsetY
be the vertical offset from the border edge of current
to the border edge of nextAncestor,
ignoring any transforms that apply to current and its ancestors.
Let translationMatrix be a new DOMMatrix representing a
translation by offsetX and offsetY.
Set transformationMatrix to the result of multiplying translationMatrix by transformationMatrix.
Otherwise, if current is a Text, set nextAncestor to current’s parent element.
Otherwise, if current is a CSSPseudoElement, set nextAncestor to current’s parent.
Set current to nextAncestor.
Return transformationMatrix.
DOMPoint point,
a GeometryNode node, and a CSSBoxType box,
run the following steps:
Let adjustedPoint be a new DOMPoint with the same
x and y as point.
If box is "margin",
adjust adjustedPoint so that it refers to the same physical point
in node’s local coordinate space,
but with coordinates measured from the top-left corner of node’s
border box rather than the top-left corner of its margin box.
If box is "padding",
adjust adjustedPoint so that it refers to the same physical point
in node’s local coordinate space,
but with coordinates measured from the top-left corner of node’s
border box rather than the top-left corner of its padding box.
If box is "content",
adjust adjustedPoint so that it refers to the same physical point
in node’s local coordinate space,
but with coordinates measured from the top-left corner of node’s
border box rather than the top-left corner of its content box.
Return adjustedPoint.
DOMPoint point,
a GeometryNode node, and a CSSBoxType box,
run the following steps:
Let adjustedPoint be a new DOMPoint with the same
x and y as point.
If box is "margin",
adjust adjustedPoint so that it refers to the same physical point
in node’s local coordinate space,
but with coordinates measured from the top-left corner of node’s
margin box rather than the top-left corner of its border box.
If box is "padding",
adjust adjustedPoint so that it refers to the same physical point
in node’s local coordinate space,
but with coordinates measured from the top-left corner of node’s
padding box rather than the top-left corner of its border box.
If box is "content",
adjust adjustedPoint so that it refers to the same physical point
in node’s local coordinate space,
but with coordinates measured from the top-left corner of node’s
content box rather than the top-left corner of its border box.
Return adjustedPoint.
The getBoxQuads(options) method must run the following steps:
Let node be this.
If node is a Document, let document be node.
Otherwise, if node is a CSSPseudoElement, let document be node’s element’s node document.
Otherwise, let document be node’s node document.
If options.relativeTo is specified,
let relativeTo be options.relativeTo.
Otherwise, let relativeTo be document.
If node is a Document, then:
Let rect be a DOMRect whose x and y are 0,
and whose width and height are the width and height
of the layout viewport.
Let quad be the result of invoking fromRect() with rect.
Append the result of invoking the convertQuadFromNode() method on relativeTo
with quad and document to result.
Otherwise, if node is a Text, then:
For each DOMRect rect returned by invoking the getClientRects() method
on a Range whose boundary-points select exactly node, in content order:
Let quad be the result of invoking fromRect() with rect.
Append the result of invoking the convertQuadFromNode() method on relativeTo
with quad and document to result.
Otherwise, for each box fragment of node, in flat tree order, run the following steps:
Let rect be a DOMRect describing the border area of
the box fragment, positioned in the fragment’s local coordinate space
with its border edge at x = 0 and y = 0.
If options.box is
"margin",
let rect instead be a DOMRect describing the fragment’s margin area
in the same local coordinate space,
with the fragment’s border edge still at x = 0 and y = 0.
If options.box is
"padding",
let rect instead be a DOMRect describing the fragment’s padding area
in the same local coordinate space,
with the fragment’s border edge still at x = 0 and y = 0.
If options.box is
"content",
let rect instead be a DOMRect describing the fragment’s content area
in the same local coordinate space,
with the fragment’s border edge still at x = 0 and y = 0.
Let quad be the result of invoking fromRect() with rect.
Append the result of invoking the convertQuadFromNode() method on relativeTo
with quad and node to result.
Return result.
Note: The points are flattened (3D transforms project to z=0),
similar to getClientRects().
p1 is always the physical top-left corner of the box,
even in right-to-left writing modes.
For Document and Text nodes,
all four values of box return the same geometry.
If a transformation matrix is not invertible
(e.g. due to a scale() of 0),
the resulting coordinates are implementation-defined.
The convertQuadFromNode(quad, from, options) method
must run the following steps:
Let node be this.
Let convertedQuad be the result of invoking fromQuad() with quad.
Let p1 be the result of invoking
convertPointFromNode() on node
with convertedQuad.p1,
from, and options.
Let p2 be the result of invoking
convertPointFromNode() on node
with convertedQuad.p2,
from, and options.
Let p3 be the result of invoking
convertPointFromNode() on node
with convertedQuad.p3,
from, and options.
Let p4 be the result of invoking
convertPointFromNode() on node
with convertedQuad.p4,
from, and options.
Return a new DOMQuad with p1, p2,
p3, and p4.
The convertRectFromNode(rect, from, options) method
must run the following steps:
Let node be this.
Let quad be the result of invoking fromRect() with rect.
Return the result of invoking
convertQuadFromNode() on node
with quad, from, and options.
The convertPointFromNode(point, from, options)
method returns a point flattened to 2D and must run the following steps,
ignoring the z and w members of point:
Let node be this.
Check the documents for coordinate conversion given node and from.
Let thisTransformToViewport be the result of getting the complete transform of node relative to null.
Let fromTransformToViewport be the result of getting the complete transform of from relative to null.
Let adjustedPoint be the result of
adjusting a point to the border box given point,
from, and options.fromBox.
Set adjustedPoint to the result of transforming adjustedPoint by fromTransformToViewport.
Set adjustedPoint to the result of transforming adjustedPoint by the inverse of thisTransformToViewport.
Return the result of adjusting a point from the border box
given adjustedPoint, node,
and options.toBox.
VisualViewport Interface[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 ;attribute EventHandler onscrollend ; };
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.
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.
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.
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.
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.
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.
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.
onscrollend is the event handler IDL attribute for the scrollend event.
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 the Window 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 the VisualViewport.
This section integrates with the event loop defined in HTML. [HTML]
Each Document has an associated list of pending scroll events, which stores pairs of (EventTarget, DOMString), 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 a snap container, run the steps to update scrollsnapchanging targets for doc with doc’s eventual snap target in the block axis as newBlockTarget and doc’s eventual snap target in the inline axis as newInlineTarget.
If (doc, "scroll") is already in doc’s pending scroll events, abort these steps.
Append (doc, "scroll") to doc’s pending scroll events.
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 a snap container, run the steps to update scrollsnapchanging targets for the element with the element’s eventual snap target in the block axis as newBlockTarget and the element’s eventual snap target in the inline axis as newInlineTarget.
If (element, "scroll") is already in doc’s pending scroll events, abort these steps.
Append (element, "scroll") to doc’s pending scroll events.
Whenever a visual viewport gets scrolled (whether in response to user interaction or by an API), the user agent must run these steps:
Let vv be the VisualViewport object that was scrolled.
Let doc be vv’s associated document.
If (vv, "scroll") is already in doc’s pending scroll events, abort these steps.
Append (vv, "scroll") to doc’s pending scroll events.
When asked to run the scroll steps for a Document doc, run these steps:
In what order are scrollend events dispatched? Ordered based on scroll start or scroll completion?
For each scrolling box box that was scrolled:
If box belongs to a viewport, let doc be the viewport’s associated Document and target be the viewport.
If box belongs to a VisualViewport, let doc be the VisualViewport’s associated document and target
be the VisualViewport. Otherwise, box belongs to an element and let doc be the element’s node document and target be the element.
If box belongs to a snap container, snapcontainer, run the update scrollsnapchange targets steps for snapcontainer.
If (target, "scrollend") is already in doc’s pending scroll events, abort these steps.
Append (target, "scrollend") to doc’s pending scroll events.
For each item (target, type) in doc’s pending scroll events, in the order they were added to the list, run these substeps:
If target is a Document, and type is "scroll" or "scrollend",
fire an event named type that bubbles at target.
Otherwise, if type is "scrollsnapchange", then:
Let blockTarget and inlineTarget be null initially.
If the scrollsnapchangeTargetBlock associated with target is a pseudo-element, set blockTarget to the owning element of that scrollsnapchangeTargetBlock.
Otherwise, set blockTarget to that scrollsnapchangeTargetBlock.
If the scrollsnapchangeTargetInline associated with target is a pseudo-element, set inlineTarget to the owning element of that scrollsnapchangeTargetInline.
Otherwise, Set inlineTarget to that scrollsnapchangeTargetInline.
Fire a SnapEvent, snapevent, named scrollsnapchange at target
and let snapevent’s snapTargetBlock and
snapTargetInline attributes be blockTarget and inlineTarget respectively.
Otherwise, if type is "scrollsnapchanging", then:
Let blockTarget and inlineTarget be null initially.
If the scrollsnapchanging block-axis target associated with target is a pseudo-element, set blockTarget to the owning element of that scrollsnapchanging block-axis target.
Otherwise, set blockTarget to that scrollsnapchanging block-axis target.
If the scrollsnapchanging inline-axis target associated with target is a pseudo-element, set inlineTarget to the owning element of that scrollsnapchanging inline-axis target.
Otherwise, set inlineTarget to that scrollsnapchanging inline-axis target.
Fire a SnapEvent, snapevent, named scrollsnapchanging at target
and let snapevent’s snapTargetBlock and
snapTargetInline attributes be blockTarget and inlineTarget, respectively.
Otherwise, fire an event named type at target.
Empty doc’s pending scroll events.
This section is non-normative.
| Event | Interface | Interesting targets | Description |
|---|---|---|---|
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.
|
scroll
| Event
| VisualViewport, Document, elements
| Fired at the VisualViewport, Document or element when the VisualViewport, viewport, or element is scrolled, respectively.
|
scrollend
| Event
| Document, elements, VisualViewport
| Fired at the VisualViewport, Document, or element when a scroll is completed: the
VisualViewport, viewport, or element has been scrolled, the scroll sequence has ended and any scroll offset changes have
been applied.
|
Some CSS features use post-layout state, like scroll position, as input to the next style and layout update.
When asked to run snapshot post-layout state steps for a Document doc, run these steps:
For each CSS feature that needs to snapshot post-layout state, take a snapshot of the relevant state in doc.
The state that is snapshot is defined in other specifications. These steps must not invalidate doc or any other Documents in such a way that other post-layout snapshotting steps can observe that such snapshotting happened. It follows that the order of which such snapshotting takes place must not matter.
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.
No new security considerations have been reported on this specification.
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.
Added Simon Fraser and Emilio Cobos Álvarez as current editors and moved Simon Pieters to former editors.
Clarified how getClientRects() handles typographic character units.
Changed how getBoundingClientRect() of Element and getBoundingClientRect() of Range handle empty rectangles.
Changed definition of offsetParent for Shadow DOM.
Allowed UAs to lie about Screen properties for privacy reasons.
Changed colorDepth and pixelDepth to return real values.
Changed 'CSS pixels' to refer to [CSS-VALUES].
Changed default values for ScrollIntoViewOptions to start and nearest and slightly changed behavior of scrollIntoView()
Added screenLeft and screenTop as aliases for screenX and screenY.
Defined overflow directions in terms of block-end and inline-end.
Renamed the arguments to resizeTo() to be width and height
Added script-triggered scroll-snap to list of scrolls affected by scroll-behavior.
Fixed a logical error in the Terminology section.
Added the "Security Considerations" and "Privacy Considerations" sections
Moved the scroll-behavior property to [CSS-OVERFLOW-3]
Adjusted the algorithm for offsetWidth and offsetHeight.
Added checkVisibility() method to Element.
Moved the scrollend event from WICG overscroll-scrollend-events to [CSSOM-VIEW-1] and added details for handling them.
Added a "get the bounding box" algorithm to getBoundingClientRect().
Introduced the VisualViewport API and related concepts.
Extended scroll into view algorithm to also work on Ranges.
Clarified whether scaled or unscaled dimensions are returned by various APIs in relation to the zoom property.
Took scroll snapping and scroll target into account for various scrolling APIs.
Added currentCSSZoom attribute to Element.
Added options parameter to caretPositionFromPoint() method.
Removed caret range concept from CaretPosition interface.
Defined post-layout snapshotting.
Made the various scrolling algorithms accept a pseudo-element.
Added container option to ScrollIntoViewOptions.
Added the scrollParent attribute.
Pinch zoom got renamed to scale factor.
The scrollIntoView() method on Element was changed and extended.
The scrollTop and scrollLeft IDL attributes on Element changed to no
longer take an object; the scroll(), scrollTo() and
scrollBy() methods were added instead.
The scrollWidth, scrollHeight, clientTop,
clientLeft, clientWidth and clientHeight IDL attributes on
Element were changed back to return integers.
The DOMRectList interface was removed.
The scrollingElement IDL attribute on Document 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 on Element was changed (for RTL).
The scrollIntoView() method on Element and scroll(),
scrollTo() and scrollBy() methods on Window take the relevant
dictionary as the first argument.
The MediaQueryList interface was changed to use regular event API and define
addListener() in terms of that.
Added "Change History" section.
Moved Glenn Adams to former editors.
Added Simon Pieters and Glenn Adams as editors and moved Anne van Kesteren to former editors.
Introduced scroll-behavior CSS property.
Added Block flow direction and inline base direction from [CSS-WRITING-MODES-3] to terminology.
Added section about zooming.
Added moveTo(), moveBy(), resizeTo(), and resizeBy() methods to Window.
Added devicePixelRatio attribute to Window.
Introduced ScrollOptions dictionary and added an options parameter to scrolling methods.
Added devicePixelRatio attribute to Window.
Added features parameter to open() method.
Added elementsFromPoint() method to Document.
Added getClientRect() method to CaretPosition.
Introduced initial draft of GeometryUtils interface.
Changed innerWidth, innerHeight, etc. to use double.
CSS transforms are now acknowledged.
Replaced ClientRect by DOMRect.
Changed colorDepth and pixelDepth to always return 24.
Removed redundant definition of terminology of other specifications, explicitly defining units (e.g. CSS pixels) and content/document content distinction.
Introduced MediaQueryList interface.
Moved the matchMedium() method of the Media to the Window interface, renamed it to matchMedia(), and changed its return type to MediaQueryList.
Removed the AbstractView and Media interfaces.
Removed the DocumentView interface and moved methods elementFromPoint() and caretRangeFromPoint() to the Document interface.
Renamed the caretRangeFromPoint() method to caretPositionFromPoint().
Introduced CaretPosition interface and changed the return type of caretPositionFromPoint() to CaretPosition.
Added the scrollIntoView() method to the Element interface.
Removed the WindowView interface and moved its attributes and methods to an AbstractView and inheriting ScreenView interface.
Added the document IDL attribute to AbstractView.
Added the scroll(), scrollTo(), and scrollBy() methods to the ScreenView interface.
Removed the ElementView interface and moved its attributes and methods to the Element and HTMLElement interfaces.
Added the defaultView IDL attribute and caretRangeFromPoint() method to the DocumentView interface.
Removed RangeView interface and instead directly extended the Range interface.
Removed the MouseEventView interface and instead directly extended the MouseEvent interface.
Renamed the TextRectangleList interface to ClientRectList and turned the item() method into an indexed getter.
Renamed the TextRectangle interface to ClientRect and added the width and height attributes.
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.