A fellow Stack Overflow member kindly created a working script that reveals a hidden div when a Youtube video completes. It's pretty cool check it out here. here. How would I take the following code and place it in the head so that I can create a short code that would reference this javascript in WordPress? Currently, its setup to run in the body of the page. WordPress does not like to work that way.
The end game is to see the embedded youtube video and then when the video completes it reveals the hidden div. I'm not convinced I'm approaching this the right way. I bow to your opinion if you think there's a better way.
Below is the code
<div id="player"></div>
<script src="http://www.youtube.com/player_api"></script>
<script>
// create youtube player
var player;
function onYouTubePlayerAPIReady() {
player = new YT.Player('player', {
height: '390',
width: '640',
videoId: '0Bmhjf0rKe8',
events: {
'onReady': onPlayerReady,
'onStateChange': onPlayerStateChange
}
});
}
// autoplay video
function onPlayerReady(event) {
event.target.playVideo();
}
// when video ends
function onPlayerStateChange(event) {
if(event.data === 0) {
$('html, body').animate({
scrollTop: $("#elementtoScrollToID").offset().top
}, 2000);
}
}
</script>
<div id='elementtoScrollToID' class='my_div'> Hello! </div>