Created
September 27, 2012 21:11
-
-
Save aergonaut/3796492 to your computer and use it in GitHub Desktop.
This file contains 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
When a mobile device is detected, the .loadVideo click event attaches a div#videoOverlay element containing the Youtube embed iframe to the document. The overlay is sized to cover the whole document and the iframe is centered inside it. | |
#videoOverlay has a click event bound after it is inserted that removes it from the document. This gets around the problem of the close button being unclickable. |
This file contains 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
$(".loadVideo").click(function() { | |
var $container, leftOff, topOff, url, videoHeight, videoWidth; | |
videoHeight = 552; | |
videoWidth = 981; | |
url = $(this).attr('href'); | |
if (navigator.userAgent.match(/(iPhone|iPad|iPod|Android)/i)) { | |
topOff = videoHeight / 2; | |
leftOff = videoWidth / 2; | |
$('body').append("<div id=\"videoOverlay\"><iframe style=\"margin-top: -" + topOff + "px; margin-left: -" + leftOff + "px;\" width=\"" + videoWidth + "\" height=\"" + videoHeight + "\" src=\"" + url + "?showinfo=0&authohide=1&autoplay=1&rel=0&wmode=opaque\" frameborder=\"0\" allowfullscreen></iframe></div>"); | |
$('#videoOverlay').click(function() { | |
return $(this).remove(); | |
}); | |
} else { | |
$('.video').fadeOut(350, function() { | |
return $(this).remove(); | |
}); | |
$("#videoRow").append('<div class="video"></div>'); | |
$container = $("#videoRow .video"); | |
$container.hide().append("<a href=\"#\" class=\"closeBtn\">Close</a><iframe width=\"" + videoWidth + "\" height=\"" + videoHeight + "\" src=\"" + url + "?showinfo=0&autohide=1&autoplay=1&rel=0&wmode=opaque\" frameborder=\"0\" allowfullscreen></iframe>").fadeIn(); | |
} | |
return false; | |
}); |
This file contains 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
#videoOverlay { | |
background: rgba(0, 0, 0, 0.8); | |
height: 100%; | |
left: 0; | |
position: fixed; | |
top: 0; | |
width: 100%; | |
z-index: 1337; } | |
#videoOverlay iframe { | |
position: relative; | |
top: 50%; | |
left: 50%; } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment