You could use this youtube iframe API. Basically what you need to do to solve your problem (I hope), and add a script to import this API. Enter it via tag:
<script
data-js="yt_api"
src="https://www.youtube.com/player_api"
></script>
In his div
containing the iframe, place an attribute id="ytplayer"
which I will use to manipulate via Javascript, this way:
<div class="row">
<!-- este id aqui -->
<div
id="ytplayer"
class="col-sm-7 wow animated rotateIn"
data-wow-duration="2s"
style="margin: 0 auto; width: 50%"
>
<iframe
id="player"
width="100%"
height="423"
src="https://www.youtube.com/embed/1lcKDZ-RJb0"
frameborder="0"
allow="accelerometer; autoplay; clipboard-write; encrypted-media; gyroscope; picture-in-picture"
allowfullscreen
></iframe>
</div>
</div>
Now comes the manipulation via Javascript. Let’s start the youtube API object with the function onYouTubePlayerAPIReady
:
<script>
let player;
const conteudoDelay = document.getElementsByClassName(
'conteudo-delay',
)[0];
// 1. ytplayer code: https://developers.google.com/youtube/player_parameters#IFrame_Player_API
function onYouTubePlayerAPIReady() {
player = new YT.Player('ytplayer', {
height: '360',
width: '640',
videoId: '1lcKDZ-RJb0',
});
}
const interval = setInterval(() => {
console.log(Math.ceil(player.playerInfo.currentTime));
if (Math.ceil(player.playerInfo.currentTime) >= 5) {
conteudoDelay.setAttribute('style', 'display: block'); // agora o section vai aparecer
clearInterval(interval); // encerra execucao do interval
}
}, 1000);
</script>
Where:
videoId
iframe video id. In your case '1lcKDZ-RJb0'
.
conteudoDelay
and the service that we will change the display: none
for display: block
after 5 seconds. I adopted 5 seconds just to facilitate the test.
That script interval
server to update every second (1000
ms) and check the elapsed time of the player, through the player.playerInfo.currentTime
. We’ll make a if
to check, in this test example, if the player time is greater than or equal to 5 seconds.
conteudoDelay.setAttribute('style', 'display: block');
we will display the Section after 5 seconds
Complete code
<div class="row">
<!-- este id aqui -->
<div
id="ytplayer"
class="col-sm-7 wow animated rotateIn"
data-wow-duration="2s"
style="margin: 0 auto; width: 50%"
>
<iframe
id="player"
width="100%"
height="423"
src="https://www.youtube.com/embed/1lcKDZ-RJb0"
frameborder="0"
allow="accelerometer; autoplay; clipboard-write; encrypted-media; gyroscope; picture-in-picture"
allowfullscreen
></iframe>
</div>
</div>
<section class="conteudo-delay" style="display: none">
<div class="row">
<div class="col-sm-8 text-center" style="margin: 0 auto; width: 50%">
<a href="#">
<button class="mt-3 btn_compra">
ATUALIZE SEU PEDIDO AGORA MESMO!
</button>
</a>
</div>
</div>
</section>
<script
data-js="yt_api"
src="https://www.youtube.com/player_api"
></script>
<script>
let player;
const conteudoDelay = document.getElementsByClassName(
'conteudo-delay',
)[0];
function onYouTubePlayerAPIReady() {
player = new YT.Player('ytplayer', {
height: '360',
width: '640',
videoId: '1lcKDZ-RJb0',
});
}
const interval = setInterval(() => {
console.log(Math.ceil(player.playerInfo.currentTime));
if (Math.ceil(player.playerInfo.currentTime) >= 5) {
conteudoDelay.setAttribute('style', 'display: block'); // agora o section vai aparecer
clearInterval(interval); // encerra execucao do interval
}
}, 1000);
</script>
Test this code and see if it solves your problem.
Obviously the code can be refactored and improved. The video id can be acquired dynamically as well, but in this case I assume Voce will manually set the video id.
Thank you very much, today I will test everything you have been through, but from what I have seen I think it will work yes, and so after the tests I will accept your answer... Thank you very much, brother!!
– WPfan
Perfect, really good, I tested it here and it worked properly @Cmtecardeal
– WPfan
@Wpfan right friend! We are here to help :D
– Cmte Cardeal
People now using this method there are giving video unavailable, know tell me if updated something?
– WPfan