How to know if an element is completely visible on viewport with js? | Sololearn: Learn to code for FREE!
Novo curso! Todo programador deveria aprender IA generativa!
Experimente uma aula grƔtis
0

How to know if an element is completely visible on viewport with js?

I am trying to trigger animation only when they are in the viewport and only once i.e. if they again get out of viewport and comeback there will be no animation, they will be at the state in which they were when the animation ended.

24th Aug 2020, 4:06 AM
Sameer Crestha
Sameer Crestha - avatar
2 Respostas
+ 2
getBoundingClientRect method returns the element's bounding box relative to the viewport you can compare it with 0 or clientWidth/clientWidth to check if its visible or not most of the broesers already support this even if the status still in Working Draft
24th Aug 2020, 5:13 AM
Rei
Rei - avatar
24th Aug 2020, 9:10 AM
Raj Chhatrala
Raj Chhatrala - avatar