Skip to content

Commit

Permalink
Ensure that out-of-viewport videos aren't played.
Browse files Browse the repository at this point in the history
Fixes dhg#15.
  • Loading branch information
alecthomas committed Sep 13, 2015
1 parent 34b3242 commit 4aa82da
Showing 1 changed file with 10 additions and 6 deletions.
16 changes: 10 additions & 6 deletions javascripts/app.js
Original file line number Diff line number Diff line change
Expand Up @@ -67,13 +67,15 @@ $(document).ready(function() {
}

function playVisibleVideos() {
// $('video').each(function(){
// this.pause();
// });

if (!isTouchDevice) {
$('video:in-viewport').each(function(){
this.play();
$('video').each(function(){
if ($(this).is(':in-viewport')) {
if (this.currentTime == 0 || this.paused || this.ended) {
this.play();
}
} else {
this.pause();
}
})
}
}
Expand Down Expand Up @@ -103,6 +105,8 @@ $(document).ready(function() {

throttledVideo = throttle(playVisibleVideos, 100)

$(window).load(throttledVideo);

$(window).scroll(function(){

// Load more JSON from scroll
Expand Down

0 comments on commit 4aa82da

Please sign in to comment.