Created
February 26, 2016 15:36
-
-
Save codedcontainer/658bec692c762fbdc30b to your computer and use it in GitHub Desktop.
YouTube API with control settings. Should change height of slide area when the video is played or stopped.
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
/* youtube video in slider */ | |
// Load the IFrame Player API code asynchronously. | |
var tag = document.createElement('script'); | |
tag.src = "https://www.youtube.com/player_api"; | |
var firstScriptTag = document.getElementsByTagName('script')[0]; | |
firstScriptTag.parentNode.insertBefore(tag, firstScriptTag); | |
// Replace the 'ytplayer' element with an <iframe> and | |
// YouTube player after the API code downloads. | |
var player; | |
function onYouTubePlayerAPIReady() { | |
player = new YT.Player('ytplayer', { | |
height: '400', | |
width: '100%', | |
videoId: 'nisAy26sItM', | |
events: { | |
'onStateChange':onPlayerStateChange | |
} | |
}); | |
} | |
//when the video starts to play move the introduction content down | |
var done = false; | |
function onPlayerStateChange(event) { | |
if ( event.data == 1) | |
{ | |
//move the introduction content down | |
$('#introContent').not('#single #introContent').animate({top: '0px' }, 500 ); | |
$('#services').animate({'margin-top': '0px'}, 500); | |
// move the article content down 300px | |
$('#single #introContent').animate({'margin-top': '142px'}); | |
// pause the slider | |
slider.slickPause(); | |
} | |
if ( event.data == -1 || event.data == 2) | |
{ | |
// move the introduction content back up | |
$('#introContent').not('#single #introContent').animate({top:'-165px'}, 500); | |
$('#services').animate({'margin-top': '-100px'}, 500); | |
// move the article content up | |
$('#single #introContent').animate({'margin-top': '0px'}); | |
line.stop(); | |
//start the slick slider | |
slider.slickPlay(); | |
} | |
if (event.data == YT.PlayerState.PLAYING && !done) { | |
setTimeout(stopVideo, 6000); | |
done = true; | |
} | |
} | |
function stopVideo() { | |
player.stopVideo(); | |
} | |
//when the video stops move the introduction content back to were it was |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment