Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Intersection Observer - Manipulación del DOM
- Loading branch information
Showing
2 changed files
with
22 additions
and
6 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
const isIntersecting = (entry) => { | ||
return entry.isIntersecting; // True -> dentro de la pantalla | ||
}; | ||
|
||
const accion = (entry) => { | ||
const nodo = entry.target; | ||
console.log("que fue manito"); | ||
|
||
// Cuando ya cargó la imagen desregistra. | ||
observer.unobserve(nodo); | ||
}; | ||
|
||
// Entries -> Todos los elemento que está observando. | ||
const observer = new IntersectionObserver((entries) => { | ||
entries.filter(isIntersecting).forEach(accion); | ||
}); | ||
|
||
export const registerImage = (imagen) => { | ||
observer.observe(imagen); | ||
}; |