Last active
October 16, 2015 06:46
-
-
Save gunlinux/b3fc50658438ddf9bd92 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
var play_visible_video = function () { | |
$('.background-video').each(function () { | |
var video = $(this); | |
var view = $(window); | |
var viewTop = view.scrollTop(); | |
var viewBottom = viewTop + view.height(); | |
var videoTop = video.offset().top; | |
var videoHeight = video.height(); | |
var videoMiddle = videoTop + 0.5 * videoHeight; | |
if ((viewBottom > videoMiddle) && (viewTop < videoMiddle)) { | |
video[0].play(); | |
video.loop = true; | |
} else { | |
video[0].pause(); | |
} | |
}); | |
}; | |
$(window).on('scroll', function () { | |
play_visible_video(); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment