gpt4 book ai didi

javascript - 倒数计时器,setDate 有问题

转载 作者:行者123 更新时间:2023-11-28 14:53:04 26 4
gpt4 key购买 nike

我目前正在通过库使用倒数计时器,具体来说 - flipclockjs。现在我可以让它在使用间隔时正常工作和倒计时,但是当尝试使用 setDate 或类似的东西时,我总是失败并且它根本无法工作。

如果这是一个新问题,我很抱歉,对这类事情来说还比较新。非常感谢任何帮助,谢谢!

这是我的代码:

<html>
<head>
<link rel="stylesheet" href="../compiled/flipclock.css">
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.10.2/jquery.min.js"></script>
<script src="../compiled/flipclock.js"></script>
</head>
<body>

<div class="clock" style="margin:2em;"></div>
<div class="message"></div>

<script type="text/javascript">
var clock;

$(document).ready(function() {
var clock;
clock = $('.clock').FlipClock({
clockFace: 'DailyCounter',
autoStart: false,
callbacks: {
stop: function() {
$('.message').html('The clock has stopped!')
}
}
});

clock.setTime(220880);
clock.setCountdown(true);
clock.start();
});
</script>

</body>

最佳答案

您可以启动一个日期,然后获取该日期和当前日期之间的秒数差异,然后启动传递差异值的 FlipClock。

var clock = $('.clock').FlipClock( diff ,{...});

$(document).ready(function() {
var d = new Date();
d.setDate(d.getDate()+2);
var curd = new Date();
var diff = (d.getTime() - curd.getTime()) / 1000; //divide by 1000 to transform miliseconds in seconds

var clock = $('.clock').FlipClock(diff,{
clockFace: 'DailyCounter',
autoStart: true,
countdown: true,
callbacks: {
stop: function() {
$('.message').html('The clock has stopped!')
}
}
});
});
<html>
<head>
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/flipclock/0.7.8/flipclock.css">

<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.10.2/jquery.min.js"></script>

<script src="https://cdnjs.cloudflare.com/ajax/libs/flipclock/0.7.8/flipclock.js"></script>
</head>
<body>
<div class="clock" style="margin:2em;"></div>
<div class="message"></div>
</body>

关于javascript - 倒数计时器,setDate 有问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/51393524/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com