Last active
May 13, 2020 11:33
-
-
Save itsmereal/621769d94f0836da86ab1fc74a18dd8b to your computer and use it in GitHub Desktop.
Load Wistia video after preview is clicked in an iframe. Modified from https://stackoverflow.com/a/47715361
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
<!-- data-embed is wistia video id --> | |
<!-- extract data-thumb https://wistia.com/support/developers/extracting-thumbnails --> | |
<div class="wistia" data-embed="919q2r7d8r" data-thumb="6b08c24a857370a2a85a9b22539429340df8db0b"> | |
<div class="play-button"></div> | |
</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 wistia = document.querySelectorAll( ".wistia" ); | |
for (var i = 0; i < wistia.length; i++) { | |
var source = "https://embed-ssl.wistia.com/deliveries/"+ wistia[i].dataset.thumb +".jpg"; | |
var image = new Image(); | |
image.src = source; | |
image.addEventListener( "load", function() { | |
wistia[ i ].appendChild( image ); | |
}( i ) ); | |
wistia[i].addEventListener( "click", function() { | |
var iframe = document.createElement( "iframe" ); | |
iframe.setAttribute( "frameborder", "0" ); | |
iframe.setAttribute( "allowfullscreen", "" ); | |
iframe.setAttribute( "mozallowfullscreen", "" ); | |
iframe.setAttribute( "webkitallowfullscreen", "" ); | |
iframe.setAttribute( "oallowfullscreen", "" ); | |
iframe.setAttribute( "msallowfullscreen", "" ); | |
iframe.setAttribute( "src", "//fast.wistia.net/embed/iframe/"+ this.dataset.embed +"?videoFoam=true" ); | |
this.innerHTML = ""; | |
this.appendChild( iframe ); | |
} ); | |
}; | |
} )(); |
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
.wistia { | |
background-color: #000; | |
margin-bottom: 30px; | |
position: relative; | |
padding-top: 56.25%; | |
overflow: hidden; | |
cursor: pointer; | |
} | |
.wistia img { | |
width: 100%; | |
top: 0; /* Change this for different ratio than 16:9 */ | |
left: 0; | |
opacity: 0.7; | |
} | |
.wistia .play-button { | |
width: 90px; | |
height: 60px; | |
background-color: #333; | |
box-shadow: 0 0 30px rgba( 0,0,0,0.6 ); | |
z-index: 1; | |
opacity: 0.8; | |
border-radius: 6px; | |
} | |
.wistia .play-button:before { | |
content: ""; | |
border-style: solid; | |
border-width: 15px 0 15px 26.0px; | |
border-color: transparent transparent transparent #fff; | |
} | |
.wistia img, | |
.wistia .play-button { | |
cursor: pointer; | |
} | |
.wistia img, | |
.wistia iframe, | |
.wistia .play-button, | |
.wistia .play-button:before { | |
position: absolute; | |
} | |
.wistia .play-button, | |
.wistia .play-button:before { | |
top: 50%; | |
left: 50%; | |
transform: translate3d( -50%, -50%, 0 ); | |
} | |
.wistia iframe { | |
height: 100%; | |
width: 100%; | |
top: 0; | |
left: 0; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment