[英]Change Text inside div after specific time
I'm having a jQuery Countdown ( http://www.littlewebthings.com/projects/countdown/ ) for a football match. 我正在进行一场足球比赛的jQuery Countdown( http://www.littlewebthings.com/projects/countdown/ )。 When the countdown complete, it display oncomplete function.
倒计时完成后,它将显示oncomplete功能。
I want the jQuery to change the 'Live' word inside the div to Full Time after 90 minutes from the Countdown Complete. 我希望jQuery在倒计时完成90分钟后将div内的“实时”改为全时。
Here is the Code 这是代码
<div id="countdown">
<div class="dash days_dash">
<span class="dash_title">days</span>
<div class="digit">0</div>
<div class="digit">0</div>
</div>
<div class="dash hours_dash">
<span class="dash_title">hours</span>
<div class="digit">0</div>
<div class="digit">0</div>
</div>
<div class="dash minutes_dash">
<span class="dash_title">minutes</span>
<div class="digit">0</div>
<div class="digit">0</div>
</div>
<div class="dash seconds_dash">
<span class="dash_title">seconds</span>
<div class="digit">0</div>
<div class="digit">0</div>
</div>
</div>
<div class="message" id="complete" style="display: none;">Live</div>
<script language="javascript" type="text/javascript">
jQuery(document).ready(function() {
$('#countdown').countDown({
targetDate: {
'day': 11,
'month': 4,
'year': 2016,
'hour': 13,
'min': 0,
'sec': 0
},
onComplete: function() {
$('#countdown').addClass('ended');
$('#complete').slideDown();
}
});
});
</script>
You could simply add 90 minutes to a date object using the following: var newDate = new Date(originalDate.getTime() + 90 * 60000);
您可以使用以下命令简单地将90分钟添加到日期对象:
var newDate = new Date(originalDate.getTime() + 90 * 60000);
Using this new date, you can then check if the current date matches or exceeds the newdate. 使用此新日期,然后可以检查当前日期是否匹配或超过新日期。 Getting the current date is done through
Date.now()
. 通过
Date.now()
获取当前日期。 Adding this all up leads to the following: 将所有这些相加会导致以下结果:
// Original date = March 30 2016 14:00:00
var minutes = 90,
originalDate = new Date(1459339200000);
timedDate = new Date(originalDate.getTime() + minutes * 60000);
// timedDate = originalDate + 90 minutes.
if (Date.now() >= timedDate) {
// We are now 90 minutes later
// Replace div text.
}
Inside the if-statement
you can replace the div text. 在
if-statement
您可以替换div文本。 I would advise to use only one div and just replace the text; 我建议仅使用一个div并仅替换文本; as opposed to having two seperate divs.
而不是拥有两个单独的div。
To build upon what @Matthjs said in the comments. 以@Matthjs在评论中所说的为基础。 This code would work well:
该代码可以很好地工作:
var specificDate = 1459346400000; //which is what March 30th 2016 is var timeleft = specificDate - Date.now(); setInterval(update, timeleft); function update(){ if (Date.now() >= specificDate) { document.getElementById("output").innerHTML = "Time's Up"; } }
<div id="output">Still got time!</div>
This will check the if loop right when the time up. 这将在时间到时检查if循环是否正确。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.