首页 > 解决方案 > 倒计时结束时显示 DIV

问题描述

倒计时完成后,下面的脚本会显示文本“EXPIRED”(您可以更改测试时间)我的问题是..

如何显示 DIV 而不是文本“EXPIRED”基本上我想嵌入来自 VIMEO 的视频:

来自 VIMEO 的视频嵌入代码。

我想也许我可以使用“倒计时完成时显示 DIV”?

我有一种感觉,我必须对这部分代码进行一些小改动?
document.getElementById("demo").innerHTML = "EXPIRED";

<div style="padding:56.25% 0 0 0;position:relative;"><iframe src="https://player.vimeo.com/video/631000875?h=612f03d2b3&amp;badge=0&amp;autopause=0&amp;player_id=0&amp;app_id=58479" frameborder="0" allow="autoplay; fullscreen; picture-in-picture" allowfullscreen style="position:absolute;top:0;left:0;width:100%;height:100%;" title="Innovate Healthcare Event"></iframe></div><script src="https://player.vimeo.com/api/player.js"></script>

<!DOCTYPE HTML>
<html>
<head>
<meta name="viewport" content="width=device-width, initial-scale=1">
<style>
p {
  text-align: center;
  font-size: 60px;
  margin-top: 0px;
}
</style>
</head>
<body>

<p id="demo"></p>

<script>
// Set the date we're counting down to
var countDownDate = new Date("Oct 20, 2021 01:30:25").getTime();

// Update the count down every 1 second
var x = setInterval(function() {

  // Get today's date and time
  var now = new Date().getTime();
    
  // Find the distance between now and the count down date
  var distance = countDownDate - now;
    
  // Time calculations for days, hours, minutes and seconds
  var days = Math.floor(distance / (1000 * 60 * 60 * 24));
  var hours = Math.floor((distance % (1000 * 60 * 60 * 24)) / (1000 * 60 * 60));
  var minutes = Math.floor((distance % (1000 * 60 * 60)) / (1000 * 60));
  var seconds = Math.floor((distance % (1000 * 60)) / 1000);
    
  // Output the result in an element with id="demo"
  document.getElementById("demo").innerHTML = days + "d " + hours + "h "
  + minutes + "m " + seconds + "s ";
    
  // If the count down is over, write some text 
  if (distance < 0) {
    clearInterval(x);
    document.getElementById("demo").innerHTML = "EXPIRED";
  }
}, 1000);
</script>

</body>
</html>

标签: countdownvimeocountdowntimer

解决方案


我希望这能帮到您。

// If the count down is over then run this function
setTimeout(function(){
document.getElementById('hiddenDiv').style.display = 'block'; 
},3000); // 3 seconds
<h2>Wait 3 seconds to see the div with the Iframe</h2>
<div id="hiddenDiv" style="display:none">
<iframe src="https://player.vimeo.com/video/253989945?h=c6db007fe5" width="640" height="360" frameborder="0" allow="autoplay; fullscreen; picture-in-picture" allowfullscreen></iframe>
</div>


推荐阅读