Nic727 Posted February 5, 2016 Share Posted February 5, 2016 Hi, How can I make a video autoplay when in sight and stop when off screen? I know that it's not very useful to use that, but for example, if I want to put an animated background on my homepage and when I scroll down to other section the video stop. Thx Link to comment Share on other sites More sharing options...
justsomeguy Posted February 5, 2016 Share Posted February 5, 2016 You can use this to get the bounding rectangle of an element: https://developer.mozilla.org/en-US/docs/Web/API/Element/getBoundingClientRect And then compare that with what is visible in the viewport, Link to comment Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now