countdown - 倒计时结束时显示 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&badge=0&autopause=0&player_id=0&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>
解决方案
我希望这能帮到您。
// 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>
推荐阅读
- c++ - c++11前类lambda函数数组字典
- android - 如何正确限制这些图像?
- javascript - react useEffect 获取数据已完成但返回值未定义
- python - 我的代码抛出关于 NoneType 的错误,但应该定义它
- java - Istio,gRPC,没有获得服务器跨度跟踪
- vb.net - 在 MVC5 控制器中,如何为 HtmlHelper 的 htmlAttributes 或 routeValues 创建 IDictionary 或 routeValueDictionary?
- c++ - 成员函数模板,用于在具有任意参数的数据成员上调用函数
- reactjs - 执行后操作:未处理的拒绝(错误):操作可能没有未定义的“类型”属性。你有没有拼错一个常数?
- javascript - 如何使用 jsx 短语连接对 html 的反应
- mysql - MySQL - 通过仅将源表中的一行聚合值附加到主机表上的每个选定行来加入