Msc1G3:Student2

From ex25
Revision as of 11:25, 25 January 2016 by Florian (Talk | contribs)

Jump to: navigation, search


Swarm3.jpg


var tag = document.createElement('script'); tag.src = "http://www.youtube.com/player_api"; var firstScriptTag = document.getElementsByTagName('script')[0]; firstScriptTag.parentNode.insertBefore(tag, firstScriptTag); var player; function playThis(elem) { player = new YT.Player(elem.attr('id'), { events: { 'onReady': function(){player.playVideo(); player.mute();} } }); }

$(window).scroll(function() { clearTimeout($.data(this, 'scrollTimer')); $.data(this, 'scrollTimer', setTimeout(function() { // do something isScrolledIntoView(); }, 250)); }); function isScrolledIntoView() { $('.collageYoutube').each(function(){ var docViewTop = $(window).scrollTop(); var docViewBottom = docViewTop + $(window).height(); var elemTop = $(this).offset().top; var elemBottom = elemTop + $(this).height(); if ((elemBottom <= docViewBottom) && (elemTop >= docViewTop)) { playThis($(this)); }else{ pauseThis($(this)); } }); }