Created
June 8, 2021 12:56
-
-
Save GuiSandoval/61dd76638d5f6cf779f3225f89e48505 to your computer and use it in GitHub Desktop.
Youtube Iframe Optimized
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
<!DOCTYPE html> | |
<html lang="pt-br"> | |
<head> | |
<meta charset="UTF-8"> | |
<meta http-equiv="X-UA-Compatible" content="IE=edge"> | |
<meta name="viewport" content="width=device-width, initial-scale=1.0"> | |
<title>Teste de desempenho de site</title> | |
<style> | |
body { | |
display: flex; | |
justify-content: center; | |
align-items: center; | |
flex-direction: column; | |
} | |
.video-embed-optimize{ | |
display: flex; | |
justify-content: center; | |
align-items: center; | |
flex-direction: column; | |
width: 100%; | |
} | |
.video-embed-optimize>iframe { | |
height: 52.2vw; | |
max-height: 275px; | |
width: 100%; | |
max-width: 560px; | |
border: 4px solid red; | |
border-radius: 40px; | |
margin: 20px 0; | |
} | |
</style> | |
</head> | |
<body> | |
<h1>Olá Mundo</h1> | |
<!-- <iframe loading="lazy" idth="560" height="315" src="https://www.youtube.com/embed/8jLHLtj_hTA" title="YouTube video player" frameborder="0" allow="accelerometer; autoplay; clipboard-write; encrypted-media; gyroscope; picture-in-picture" allowfullscreen></iframe> | |
<iframe loading="lazy" idth="560" height="315" src="https://www.youtube.com/embed/8jLHLtj_hTA" title="YouTube video player" frameborder="0" allow="accelerometer; autoplay; clipboard-write; encrypted-media; gyroscope; picture-in-picture" allowfullscreen></iframe> | |
<iframe loading="lazy" idth="560" height="315" src="https://www.youtube.com/embed/8jLHLtj_hTA" title="YouTube video player" frameborder="0" allow="accelerometer; autoplay; clipboard-write; encrypted-media; gyroscope; picture-in-picture" allowfullscreen></iframe> | |
<iframe loading="lazy" idth="560" height="315" src="https://www.youtube.com/embed/8jLHLtj_hTA" title="YouTube video player" frameborder="0" allow="accelerometer; autoplay; clipboard-write; encrypted-media; gyroscope; picture-in-picture" allowfullscreen></iframe> | |
<iframe loading="lazy" idth="560" height="315" src="https://www.youtube.com/embed/8jLHLtj_hTA" title="YouTube video player" frameborder="0" allow="accelerometer; autoplay; clipboard-write; encrypted-media; gyroscope; picture-in-picture" allowfullscreen></iframe> | |
<iframe loading="lazy" idth="560" height="315" src="https://www.youtube.com/embed/8jLHLtj_hTA" title="YouTube video player" frameborder="0" allow="accelerometer; autoplay; clipboard-write; encrypted-media; gyroscope; picture-in-picture" allowfullscreen></iframe> | |
<iframe loading="lazy" idth="560" height="315" src="https://www.youtube.com/embed/8jLHLtj_hTA" title="YouTube video player" frameborder="0" allow="accelerometer; autoplay; clipboard-write; encrypted-media; gyroscope; picture-in-picture" allowfullscreen></iframe> | |
<iframe loading="lazy" idth="560" height="315" src="https://www.youtube.com/embed/8jLHLtj_hTA" title="YouTube video player" frameborder="0" allow="accelerometer; autoplay; clipboard-write; encrypted-media; gyroscope; picture-in-picture" allowfullscreen></iframe> --> | |
<div class="video-embed-optimize" data-id-video="8jLHLtj_hTA"></div> | |
<div class="video-embed-optimize" data-id-video="BrY6a-lsLp8"></div> | |
<div class="video-embed-optimize" data-id-video="q8VfRFcnLy0"></div> | |
<div class="video-embed-optimize" data-id-video="8jLHLtj_hTA"></div> | |
<div class="video-embed-optimize" data-id-video="8jLHLtj_hTA"></div> | |
<div class="video-embed-optimize" data-id-video="8jLHLtj_hTA"></div> | |
<div class="video-embed-optimize" data-id-video="8jLHLtj_hTA"></div> | |
<div class="video-embed-optimize" data-id-video="8jLHLtj_hTA"></div> | |
<script> | |
const video1 = document.querySelector("#video-1"); | |
const allYoutubeDivs = document.querySelectorAll(".video-embed-optimize"); | |
for (const singleDivYT of allYoutubeDivs) { | |
const idVideo = singleDivYT.getAttribute("data-id-video"); | |
singleDivYT.appendChild(generateVideoHTML(idVideo)); | |
} | |
function generateVideoHTML(idVideo) { | |
const iFrame = document.createElement('iframe'); | |
iFrame.src = "https://www.youtube.com/embed/" + idVideo; | |
iFrame.srcdoc = "<style>*{padding:0;margin:0;overflow:hidden}html,body{height:100%}img,span{position:absolute;width:100%;top:0;bottom:0;margin:auto;background-repeat: no-repeat;background-size: cover;}span{height:1.5em;text-align:center;font:48px/1.5 sans-serif;color:white;text-shadow:0 0 0.5em black}</style><a href=https://www.youtube.com/embed/" + idVideo + "?autoplay=1><img src=https://img.youtube.com/vi/" + idVideo + "/hqdefault.jpg alt='Video The Dark Knight Rises: What Went Wrong? – Wisecrack Edition'><span>▶</span></a>"; | |
iFrame.frameBorder = 0; | |
iFrame.controls = 0; | |
iFrame.allow = "accelerometer; autoplay; encrypted-media; gyroscope; picture-in-picture"; | |
iFrame.allowFullscreen = true; | |
return iFrame; | |
} | |
</script> | |
</body> | |
</html> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment