-
-
Save yoonwaiyan/c18c5d544916890fec4d to your computer and use it in GitHub Desktop.
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
.video { position: relative; padding-bottom: 56.25%; /* 16:9 */ height: 0; } | |
.video img { position: absolute; display: block; top: 0; left: 0; width: 100%; height: 100%; z-index: 20; cursor: pointer; } | |
.video:after { content: ""; position: absolute; display: block; | |
background: url(play-button.png) no-repeat 0 0; | |
top: 45%; left: 45%; width: 46px; height: 36px; z-index: 30; cursor: pointer; } | |
.video iframe { position: absolute; top: 0; left: 0; width: 100%; height: 100%; } | |
/* image poster clicked, player class added using js */ | |
.video.player img { display: none; } | |
.video.player:after { display: none; } |
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
<div class="video"> | |
<img src="poster.jpg"> | |
<!-- <iframe width="940" height="529" src="http://www.youtube.com/embed/rRoy6I4gKWU?autoplay=1" frameborder="0" allowfullscreen></iframe>--> | |
</div> |
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
$(function() { | |
var videos = $(".video"); | |
videos.on("click", function(){ | |
var elm = $(this), | |
conts = elm.contents(), | |
le = conts.length, | |
ifr = null; | |
for(var i = 0; i<le; i++){ | |
if(conts[i].nodeType == 8) ifr = conts[i].textContent; | |
} | |
elm.addClass("player").html(ifr); | |
elm.off("click"); | |
}); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment