Skip to content

[nodesFromRect] Adding threshold? #52

@keithamus

Description

@keithamus

IntersectionObserver adds a threshold parameter to allow the iteration cycle to discard nodes which don't sufficiently overlap the Rect. So for example a value of 0.0 will mean a node which intersects a rect by even 1 pixel will not be discarded, while 1.0 means the entirety of pixels would need to intersect the rect to not be discarded.

This can be ergonomically useful for developers who might end up doing these checks themselves (and in doing so can sometimes accidentally force layout). Meanwhile engines will have already flushed layout on nodes checked (to get their bounding rect) and so the intersection computation comes quite cheap (at this point in time it's essentially multiplication & division).

So this would be:

dictionary NodesFromRectOptions {
    sequence<ShadowRoot> shadowRoots = [];
    double threshold = 0;
}

Which would allow developers to do for e.g.:

let visibleOnScreen = document.nodesFromRect(
	new DOMRect(0, 0, window.screen.width, window.screen.height),
	{ threshold: 0.25 }
)

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions