wordpress - 根据日期和时间显示文本
问题描述
我有一个显示“嵌入视频”的倒计时,但我想在“倒计时完成后您将看到视频”上方添加标题
如何在其中添加标题,以便在倒计时完成时标题会消失?或者,也许您有一个新代码来根据日期和时间显示标题?
<html>
<head>
<meta name="viewport" content="width=device-width, initial-scale=1">
<style>
p {
text-align: center;
font-size: 60px;
margin-top: 0px;
color: white;
}
</style>
</head>
<body>
<p id="demo"></p>
<script>
// Set the date we're counting down to
var countDownDate = new Date("Oct 20, 2021 09:42:10").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 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>'
}
}, 1000);
</script>
</body>
</html>
解决方案
如果您想在计时器到时删除标题,请尝试此操作
if (distance < 0) {
clearInterval(x);
document.getElementById('title').style.display="none"; // add this line.
document.getElementByIdd("demo").innerHTML =
'<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>'
}
推荐阅读
- java - 是否有一种语法可以使向 JPanel 添加新组件特别快速/高效?
- bash - 如何不在终端上显示我的程序
- javascript - 扩展第三方包声明时打字稿错误重复标识符
- php - 尝试使用 composer 将 sylius/product-bundle 安装到我的 Symfony 5.3 项目时出现问题
- apache-spark - 如何根据索引组合生成数据集?
- sql - LIKE 运算符两列 clickhouse
- flutter - 在哪里初始化块?
- flutter - 在颤动中更改单个导航栏项(BottomNavigationBarItem)的样式?
- database - sqflite - 在 null 上调用了方法“插入”
- java - 在 Linux(不是 Ubuntu 或 Debian)上运行 Java Swing 应用程序的步骤是什么?