diff --git a/index.bs b/index.bs index 295e3ca..34d9578 100644 --- a/index.bs +++ b/index.bs @@ -230,42 +230,14 @@ interface IntersectionObserver { : new IntersectionObserver(callback, options) :: - 1. Let |this| be a new {{IntersectionObserver}} object - 2. Set |this|'s internal {{[[callback]]}} slot to |callback|. - 3. Attempt to parse a root margin - from |options|.{{IntersectionObserverInit/rootMargin}}. - If a list is returned, - set |this|'s internal {{[[rootMargin]]}} slot to that. - Otherwise, throw a {{SyntaxError}} exception. - 4. Let |thresholds| be a list equal to - |options|.{{IntersectionObserverInit/threshold}}. - 5. If any value in |thresholds| is less than 0.0 or greater than - 1.0, throw a {{RangeError}} exception. - 6. Sort |thresholds| in ascending order. - 7. If |thresholds| is empty, append 0 to |thresholds|. - 8. The {{IntersectionObserver/thresholds}} attribute getter will return - this sorted |thresholds| list. - 9. Return |this|. + Return the result of running the initialize a new IntersectionObserver + algorithm, providing |callback| and |options|. : observe(target) :: - 1. If |target| is in |this|'s internal {{[[ObservationTargets]]}} slot, - return. - 2. Let |intersectionObserverRegistration| be - an {{IntersectionObserverRegistration}} record - with an {{IntersectionObserverRegistration/observer}} property set to |this|, - a {{IntersectionObserverRegistration/previousThresholdIndex}} property set to -1, - and a {{IntersectionObserverRegistration/previousIsIntersecting}} property set to false. - 3. Append |intersectionObserverRegistration| - to |target|'s internal {{[[RegisteredIntersectionObservers]]}} slot. - 4. Add |target| to |this|'s internal {{[[ObservationTargets]]}} slot. - 5. Schedule an iteration of the event loop - in the {{IntersectionObserver/root}}'s browsing context. + Run the observe a target Element algorithm, providing |this| and |target|. : unobserve(target) :: - 1. Remove the {{IntersectionObserverRegistration}} record - whose {{IntersectionObserverRegistration/observer}} property is equal to |this| - from |target|'s internal {{[[RegisteredIntersectionObservers]]}} slot. - 2. Remove |target| from |this|'s internal {{[[ObservationTargets]]}} slot. + Run the unobserve a target Element algorithm, providing |this| and |target|. Note: {{MutationObserver}} does not implement {{unobserve()}}. For {{IntersectionObserver}}, {{unobserve()}} addresses the @@ -540,6 +512,56 @@ which is a list of four pixel lengths or percentages.

Algorithms

+

Initialize a new IntersectionObserver

+ +To initialize a new IntersectionObserver, given an {{IntersectionObserverCallback}} |callback| +and an {{IntersectionObserverInit}} dictionary |options|, run these steps: + +1. Let |this| be a new {{IntersectionObserver}} object +2. Set |this|'s internal {{[[callback]]}} slot to |callback|. +3. Attempt to parse a root margin + from |options|.{{IntersectionObserverInit/rootMargin}}. + If a list is returned, + set |this|'s internal {{[[rootMargin]]}} slot to that. + Otherwise, throw a {{SyntaxError}} exception. +4. Let |thresholds| be a list equal to + |options|.{{IntersectionObserverInit/threshold}}. +5. If any value in |thresholds| is less than 0.0 or greater than + 1.0, throw a {{RangeError}} exception. +6. Sort |thresholds| in ascending order. +7. If |thresholds| is empty, append 0 to |thresholds|. +8. The {{IntersectionObserver/thresholds}} attribute getter will return + this sorted |thresholds| list. +9. Return |this|. + +

Observe a target Element

+ +To observe a target Element, given an {{IntersectionObserver}} |observer| +and an {{Element}} |target|, follow these steps: + +1. If |target| is in |observer|'s internal {{[[ObservationTargets]]}} slot, + return. +2. Let |intersectionObserverRegistration| be + an {{IntersectionObserverRegistration}} record + with an {{IntersectionObserverRegistration/observer}} property set to |observer|, + a {{IntersectionObserverRegistration/previousThresholdIndex}} property set to -1, + and a {{IntersectionObserverRegistration/previousIsIntersecting}} property set to false. +3. Append |intersectionObserverRegistration| + to |target|'s internal {{[[RegisteredIntersectionObservers]]}} slot. +4. Add |target| to |observer|'s internal {{[[ObservationTargets]]}} slot. +5. Schedule an iteration of the event loop + in the {{IntersectionObserver/root}}'s browsing context. + +

Unobserve a target Element

+ +To unobserve a target Element, given an {{IntersectionObserver}} |observer| +and an {{Element}} |target|, follow these steps: + +1. Remove the {{IntersectionObserverRegistration}} record + whose {{IntersectionObserverRegistration/observer}} property is equal to |this| + from |target|'s internal {{[[RegisteredIntersectionObservers]]}} slot, if present. +2. Remove |target| from |this|'s internal {{[[ObservationTargets]]}} slot, if present +

Queue an Intersection Observer Task