Closed grechihinrhp closed 6 months ago
The code described above is expected to track the first intersection of the observed element.
However, according to the current ESLIntersectionTarget
spec, it will produce ESLIntersectionEvent (intersects)
each time the IntersectionObserver
callback is called.
So, the original intersects
event will (and should) be produced each time the intersection observer configuration is satisfied (for both positive and negative intersections, with all of the passed ratios).
The recommended way to handle this expected behavior is as follows:
@listen({
event: 'intersects',
target: ESLIntersectionTarget.for
})
_onIntersect(e: ESLIntersectionEvent): void {
if (e.isIntersecting) {
// do something
// Unsubscribe manually
this.$$off(this._onIntersect);
}
}
Note: This is the most common way to handle such scenarios and should continue to be used to handle complex intersection settings and conditions.
However, the following proposal was discussed and approved (as a POC) by the @exadel-inc/esl-core-maintainers :
To simplify the most common case described above, it is proposed to introduce intersects:in
and intersects:out
events:
intersects:in
- should be triggered each time a positive intersection condition is met (including the initial call).intersects:out
- should be triggered each time a negative intersection condition is met (including the initial call).@listen({
event: 'intersects:in',
target: ESLIntersectionTarget.for,
once: true
}) // Happens once a positive intersection happens
_onIntersect(e: ESLIntersectionEvent): void {
if (e.isIntersecting) {
// do something
}
}
isIntersecting
marker; it should be considered whether our responsibility includes checking intersection ratio as well.:tada: This issue has been resolved in version 5.0.0-beta.14 :tada:
The release is available on:
Your semantic-release bot :package::rocket:
:tada: This issue has been resolved in version 4.17.0 :tada:
The release is available on:
Your semantic-release bot :package::rocket:
Input Code
Expected behavior/code
intersects
event should be triggered when target element intersects viewport first timeEnvironment