Skip to content

Instantly share code, notes, and snippets.

@sumonst21
Created April 29, 2019 00:45
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save sumonst21/1ed1dd95e8c90ac74410975aa4bbe7a5 to your computer and use it in GitHub Desktop.
Save sumonst21/1ed1dd95e8c90ac74410975aa4bbe7a5 to your computer and use it in GitHub Desktop.
Placeholder image for a Video
<div class="video">
<img src="http://lorempixel.com/500/281/technics/1/" data-video="https://player.vimeo.com/video/65158674?autoplay=1">
<div class="play"><i class="icon-play icon-2x"></i></div>
</div>

Placeholder image for a Video

Placeholder image is replaced by the YouTube or Vimeo iframe when clicked on the .play element.

A Pen by Sumon Islam on CodePen.

License.

$('.play').click(function() {
video = '<iframe width="500" height="281" frameborder="0" src="' + $('img').attr('data-video') + '"></iframe>';
$('.video').replaceWith(video);
});
<script src="//cdnjs.cloudflare.com/ajax/libs/jquery/2.1.3/jquery.min.js"></script>
/* External Resources: Font Awesome (icon font) https://netdna.bootstrapcdn.com/font-awesome/3.2.0/css/font-awesome.min.css */
.video {
position: relative;
height: 281px;
width: 500px;
background: #73AF96;
position: absolute;
}
.video img {
opacity: .65;
}
.play {
height: 80px;
width: 120px;
position: absolute;
text-align: center;
cursor: pointer;
border-radius: 5px;
/*Centering*/
margin: -40px 0 0 -60px;
left: 50%;
top: 50%;
display: block;
background: #FA614D;
transition: background-color 0.5s ease;
color: white;
}
.play:hover {
background: #C31A1F;
}
.icon-play {
line-height: 80px;
}
.icon-play:before {
cursor: pointer;
}
<link href="https://netdna.bootstrapcdn.com/font-awesome/3.2.0/css/font-awesome.min.css" rel="stylesheet" />
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment