As indicated there , you can check when the window is focused, that is, the user clicked (but did not view it). How do you implement it?
You choose id / class / tag, whatever. Style it, with animation as well. When this window is focused, you apply id / class to the element or create a new element with the / id / class tag. After adding the class, you either cancel the onfocus function, or check with the variable created for this purpose.
Example:
window.onfocus=function(){ window.onfocus=null; document.getElementById("toBeAnimated").className="animatable"; }
#toBeAnimated{ font-size:25px; } .animatable{ transition: background-color 250ms linear; background-color:black; transition: color 250ms linear; color:white; }
<div id="toBeAnimated">Focus on the snippet to animate me!</div>
Another option: you can apply this function to the onscroll event, for example, when the user starts scrolling your page.
nicael
source share