starting video when the page is scrolled to it
authorAnthony Talarico <talarico@gaslightmedia.com>
Fri, 9 Feb 2018 12:58:31 +0000 (07:58 -0500)
committerAnthony Talarico <talarico@gaslightmedia.com>
Fri, 9 Feb 2018 12:58:31 +0000 (07:58 -0500)
only playing the footer video if it is in view

front-page.php
js/app.js
js/custom/pageSetup.js

index 289159c..258374c 100644 (file)
@@ -21,7 +21,7 @@
         </div>
         <?php get_template_part('parts/blog-feed-front');?>
         <div id="video">
-        <video id="front-page-video" playsinline autoplay loop controls muted>
+        <video id="front-page-video" playsinline loop controls muted>
             <source src="<?php bloginfo('template_url'); ?>/assets/winter_video.mp4" type="video/mp4">
         </video>
             <!-- <iframe width="560" height="315" src="https://www.youtube.com/embed/etv3-mo9Q-Y?rel=0" frameborder="0" allowfullscreen></iframe> -->
index f730ca2..cbb11c0 100644 (file)
--- a/js/app.js
+++ b/js/app.js
@@ -249,6 +249,7 @@ $(document).ready(function () {
 
         }
     $(window).resize(function(e) {
+        
         windowWidth = $(this).width();
         if (windowWidth < 1025) {
             bigScreen.detach();
@@ -268,5 +269,16 @@ $(document).ready(function () {
         var goToUrl = $(this).children('a').attr("href");
         $(location).attr('href',goToUrl);
     });
-
+    var video = $('#front-page-video');
+    $(window).on("scroll", function(){
+        video.get(0).play();
+    })
+    $.fn.isInViewport = function() {
+        var elementTop = $(this).offset().top;
+        var elementBottom = elementTop + $(this).outerHeight();
+        var viewportTop = $(window).scrollTop();
+        var viewportBottom = viewportTop + $(window).height();
+        return [elementBottom > viewportTop && elementTop < viewportBottom,$(this)];
+    };
 });
index 40720ec..6adc236 100644 (file)
@@ -46,6 +46,7 @@ $(document).ready(function () {
 
         }
     $(window).resize(function(e) {
+        
         windowWidth = $(this).width();
         if (windowWidth < 1025) {
             bigScreen.detach();
@@ -65,5 +66,16 @@ $(document).ready(function () {
         var goToUrl = $(this).children('a').attr("href");
         $(location).attr('href',goToUrl);
     });
-
+    var video = $('#front-page-video');
+    $(window).on("scroll", function(){
+        video.get(0).play();
+    })
+    $.fn.isInViewport = function() {
+        var elementTop = $(this).offset().top;
+        var elementBottom = elementTop + $(this).outerHeight();
+        var viewportTop = $(window).scrollTop();
+        var viewportBottom = viewportTop + $(window).height();
+        return [elementBottom > viewportTop && elementTop < viewportBottom,$(this)];
+    };
 });