Pen Settings

HTML

CSS

CSS Base

Vendor Prefixing

Add External Stylesheets/Pens

Any URL's added here will be added as <link>s in order, and before the CSS in the editor. If you link to another Pen, it will include the CSS from that Pen. If the preprocessor matches, it will attempt to combine them before processing.

+ add another resource

JavaScript

Babel includes JSX processing.

Add External Scripts/Pens

Any URL's added here will be added as <script>s in order, and run before the JavaScript in the editor. You can use the URL of any other Pen and it will include the JavaScript from that Pen.

+ add another resource

Packages

Add Packages

Search for and use JavaScript packages from npm here. By selecting a package, an import statement will be added to the top of the JavaScript editor for this package.

Behavior

Save Automatically?

If active, Pens will autosave every 30 seconds after being saved once.

Auto-Updating Preview

If enabled, the preview panel updates automatically as you code. If disabled, use the "Run" button to update.

Format on Save

If enabled, your code will be formatted when you actively save your Pen. Note: your code becomes un-folded during formatting.

Editor Settings

Code Indentation

Want to change your Syntax Highlighting theme, Fonts and more?

Visit your global Editor Settings.

HTML

              
                <!DOCTYPE html>
<html lang="en"><head>
<meta name="generator" content="Hugo 0.53">
<meta http-equiv="content-type" content="text/html; charset=UTF-8">
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<title>Tezify | Youtube Test</title>
</head>
<body>
<div>
<a id="youtube-link" class="youtube" href="javascript:void(0);" onclick="showVideo();">
<img id="youtube-thumb" src="https://img.youtube.com/vi/e1gAyQuIFQo/mqdefault.jpg" width="560" style="max-width:100%" alt="{ video title here }" />
</a>
 <iframe style="display:none;max-width:100%;" id="youtube-embed-iframe" width="560" height="315" data-src="https://www.youtube.com/embed/e1gAyQuIFQo?enablejsapi=1" frameborder="0" allow="accelerometer; autoplay; encrypted-media; gyroscope; picture-in-picture" allowfullscreen></iframe>
</div>
<h1>Youtube Video Demo</h1>
<p>This page demonstrates fast loading of Youtube video.</p>
</body>
</html>

              
            
!

CSS

              
                .youtube {
    position: relative;
    display: inline-block;
}

.youtube:before {
    content: "";
    position: absolute;
    width: 100%;
    height: 100%;
    z-index: 10;
    background: transparent url('https://upload.wikimedia.org/wikipedia/commons/e/e1/YouTube_play_buttom_icon_%282013-2017%29.svg') center center no-repeat;
        background-size: 30%;
}

              
            
!

JS

              
                var player;
function onYouTubeIframeAPIReady() {
    player = new YT.Player('youtube-embed-iframe', {
      height: '315',
      width: '560',
      videoId: 'e1gAyQuIFQo',
      events: {
        'onReady': onPlayerReady,
      }
    });
}

function onPlayerReady(event) {
        console.log('player ready');
    event.target.playVideo();
}


function stopVideo() {
    player.stopVideo();
}

function showVideo()
{
        document.getElementById('youtube-link').style.display = "none";
        document.getElementById('youtube-embed-iframe').style.display="block";
        document.getElementById('youtube-thumb').style.display="none";
        let ifr = document.getElementById('youtube-embed-iframe');
        ifr.setAttribute('src',ifr.getAttribute('data-src'))
        var tag = document.createElement('script');
        tag.src = "https://www.youtube.com/iframe_api";
        var firstScriptTag = document.getElementsByTagName('script')[0];
        firstScriptTag.parentNode.insertBefore(tag, firstScriptTag);
}

              
            
!
999px

Console