Community Forums › Forums › Archived Forums › Design Tips and Tricks › INCLUDE HTML, CSS AND JAVASCRIPT
- This topic has 1 reply, 2 voices, and was last updated 3 years, 9 months ago by Matt M..
-
AuthorPosts
-
January 9, 2021 at 1:22 pm #502594NachocaParticipant
Hi all,
Can anyone help me to include some codes in my page? I have seen that Youtube videos size is aroung 500Kb each. Reviewing on the internet, I have found a solution to reduce this size but I would have to include code in HTLM, CSS and Javascript.
I am using Metro Pro Theme.
If there is an easy way to reduce size, I will appreciate some feedback.
The code that I have to include is the following in each page with video but maybe there is a way to include part of it as General.
Below you can see the code that I'm talking about in case it helps.
Best Regards,
HTML
<div class="contenedor">
<div class="reproductor" data-id="here I will include each video code"></div>
</div>CSS
<style>
.contenedor{
display: block;
margin: 20px auto;
width: 100%;
max-width: 600px;
}
.reproductor {
display: block;
width: 100%;
height: 100%;
padding-bottom: 56.25%;
overflow: hidden;
position: relative;
cursor: hand;
cursor: pointer;
}
img.imagen-previa {
display: block;
left: 0;
bottom: 0;
margin: auto;
max-width: 100%;
width: 100%;
position: absolute;
right: 0;
top: 0;
height: auto
}
div.youtube-play {
height: 64px;
width: 64px;
left: 50%;
top: 50%;
margin-left: -36px;
margin-top: -36px;
opacity:0.7;
position: absolute;
background: url("https://cdn2.iconfinder.com/data/icons/social-icons-color/512/youtube-64.png") no-repeat;
}
div.youtube-play:hover{
opacity:1;
}
#youtube-iframe {
width: 100%;
height: 100%;
position: absolute;
top: 0;
left: 0;
}
</style>JAVASCRIPT
<script>
https://sonidodecuerdas.com/
(function() {
var v = document.getElementsByClassName("reproductor");
for (var n = 0; n < v.length; n++) {
var p = document.createElement("div");
p.innerHTML = labnolThumb(v[n].dataset.id);
p.onclick = labnolIframe;
v[n].appendChild(p);
}
})();
function labnolThumb(id) {
return '<div class="youtube-play"></div>';
}
function labnolIframe() {
var iframe = document.createElement("iframe");
iframe.setAttribute("src", "//www.youtube.com/embed/" + this.parentNode.dataset.id + "?autoplay=1&autohide=2&border=0&wmode=opaque&enablejsapi=1&controls=0&showinfo=0");
iframe.setAttribute("frameborder", "0");
iframe.setAttribute("id", "youtube-iframe");
this.parentNode.replaceChild(iframe, this);
}
</script>January 21, 2021 at 11:18 am #502775Matt M.ParticipantThe easiest way to include in a specific page is by using the Gutenberg 'custom html' block. Then literally just copy and paste that code you shared into the block. I'd put it at the top of your page.
I use this trick all the time to include custom CSS for an element that's only on one page, to avoid weighing down my main stylesheet.
-
AuthorPosts
- The forum ‘Design Tips and Tricks’ is closed to new topics and replies.