我想使用flipclock作为反向计数器。计时器应该从hh:mm:ss(例如,19:40:46)到00:00:00开始。
以下是代码
var clock;
$(document).ready(function() {
// Grab the current date
var currentDate = new Date();
// Set some date in the future. In this case, it's always Jan 1
var futureDate = new Date(currentDate.getFullYear() + 1, 0, 1);
// Calculate the difference in seconds between the future and current date
var diff = futureDate.getTime() / 1000 - currentDate.getTime() / 1000;
// Instantiate a coutdown FlipClock
clock = $('.dw_clock').FlipClock(diff, {
clockFace: 'DailyCounter',
countdown: true,
showSeconds: true
});
});
我不想要约会。此外,时间值应该从MySQL获取,并且在登录时对于不同的用户是不同的。从PHP-MySQL,我有:
function timeToPlay(&$smarty){
$sqlStr = "select timediff('24:00:00', time(taken_on)) as timeRemaining,
hour(timediff('24:00:00', time(taken_on))) as hour,
minute(timediff('24:00:00', time(taken_on))) as minute,
second(timediff('24:00:00', time(taken_on))) as second
FROM profile_sicc_exer_score where user_id=".$_SESSION['user_id']."
order by id desc limit 1";
$sqlQuery = mysql_query($sqlStr) or die(mysql_error()."<hr>".$sqlStr);
if ( mysql_num_rows($sqlQuery) ) {
$timeToPlayNext = mysql_fetch_assoc($sqlQuery);
$smarty->assign("timeRemaining",$timeToPlayNext['timeRemaining']);
$smarty->assign("hour",$timeToPlayNext['hour']);
$smarty->assign("minute",$timeToPlayNext['minute']);
$smarty->assign("second",$timeToPlayNext['second']);
}
}
从上面的代码中,我得到(示例)
的值如何使用上述Flipclock代码中的值javascript / jquery ...
答案 0 :(得分:0)
对于flipClock,您必须将clockFace更改为“HourlyCounter”,因此它不会显示日期。
之后,拥有php变量,你可以将它们“回显”到javascript代码中,例如,在网页的末尾,你可以把:
<script>
clock.setTime(<?php echo $hour*3600+$minute*60+$second; ?>);
</script>
你可以随时将它放在“onload”函数或类似的东西中,但它应该可以正常工作。
您没有留下有关计数器显示的实际html页面的任何详细信息,因此我无法帮助您进一步说明这一点。
祝你好运!