【问题标题】:Show DIV when Countdown finish倒计时结束时显示 DIV
【发布时间】:2021-12-06 20:44:36
【问题描述】:

倒计时结束后,下面的脚本会显示文本“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>

【问题讨论】:

    标签: countdown vimeo countdowntimer


    【解决方案1】:

    希望对您有所帮助。

    // 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>

    【讨论】:

      【解决方案2】:

      已修复!我设法修复它,这是解决方案..

      从您的特定日期开始倒计时以显示 DIV(您可以在此 div 内放置任何内容)

      <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 22, 2021 02:22: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 =
        '<div><iframe src="https://player.vimeo.com/video/631000875?h=612f03d2b3&amp;badge=0&amp;autopause=0&amp;player_id=0&amp;app_id=58479" width="1280" height="720" frameborder="0" allow="autoplay; fullscreen; picture-in-picture" allowfullscreen title="Innovate Healthcare Event"></iframe></div>'
        }
      }, 1000);
      </script>
      
      </body>
      </html>

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2023-04-10
        • 2019-01-16
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多