根据日期和时间显示文本



我有一个倒计时显示嵌入视频"但是我想在上面添加标题"当倒计时完成时,您将看到视频">

我如何添加标题,这使标题将消失时倒计时完成?或者您可能有一个新的代码来显示基于日期和时间的标题?

<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&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>'
}
}, 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&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>'
}

最新更新