I am creating a site which contains multiple YouTube iframes that appear within Zurb Foundations reveal modals. The finished version of the site will have around 30 videos which will create a heavy load and will deteriorate the page speed. To counter this I was planning to use lazyYT.js to lazy load the videos It all works great on the first load, however after opening a modal and finishing playing then closing the modal the video will restart and play in the background.
I have tried multiple variations in lazy loading with no success. I assume the problem is with reveal not terminating the iframe correctly or that the lazy load gets triggered incorrectly.
Fiddle http://jsfiddle.net/j43aepqh/6/
HTML:
<!-- Triggers the modals -->
<a href="#" data-reveal-id="videoModal" class="radius button">Example Modal w/Video…</a>
<div id="videoModal" class="reveal-modal large" data-reveal="">
<h2>This modal has video</h2>
<div class="flex-video widescreen vimeo" style="display: block;">
<div class="js-lazyYT" data-youtube-id="_oEA18Y8gM0" data-width="560" data-height="315" data-parameters="rel=0"></div>
</div>
<a class="close-reveal-modal">×</a>
</div>
<!-- Reveal Modals end -->
<script>$(document).foundation();</script>
<script>$('.js-lazyYT').lazyYT();</script>
This is driving me mad as I can't get my head around what is happening and how to resolve the issue.
Is this the correct valid way of posting videos on a site? I am open to any other methods of posting multiple videos on a single page using a modal and YouTubes iframe embed without causing serious page speed problems.
Are there any good scripts for deferring the load of iframes or a way to load them one by one?
Any help or suggestions would be appreciated.
p.s first time using stackoverflow, hope I'm doing it right
I experienced the same problem. I was able to get lazy loading to work using a different script, found here: http://www.labnol.org/internet/light-youtube-embeds/27941/
Let me know if it works for you!
Brent