Created
June 15, 2017 15:19
-
-
Save dgrebb/10fc9f3140a26b355b9056468c8f5c5f to your computer and use it in GitHub Desktop.
viewport scroll in/out event
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
/** | |
* Play or pause video based on visibility in window viewport. | |
* | |
* @param {any} video The video element. | |
* | |
* @memberof TabbedVideo | |
*/ | |
toggleVideoPlayback(video) { | |
var windowHeight = window.innerHeight, | |
videoTop = video.getBoundingClientRect().top, | |
videoBottom = videoTop + video.offsetHeight; | |
if ( videoTop < windowHeight && videoBottom > 0 ) { | |
video.play(); | |
} | |
if ( videoBottom <= 0 || videoTop > windowHeight ) { | |
video.pause(); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment