admin管理员组文章数量:1414604
I added a flipclock countdown timer to my site and I want a way to fire an event every minute so that I can make a change to an element in the source. I tried adding an alert in the code to see if the callback ever gets fired but I am pretty sure I do not quite understand the documentation of the callback method. I referenced the flipclock.min.js and the flipclock.css and I am able to get the clock to countdown and everything i just need to have an event fire after every minute. This is where you can find the documentation and the download: Flipclock.js
This is the javascript code that i currently have:
<script type="text/javascript">
var clock = $('#clock').FlipClock(3600,{
countdown: true,
callbacks: {
_interval: function () {
var time = clock.getTime().time;
alert(time);
if (time % 60 == 0) {
//Change element
}
}
}
});
</script>
Here is the html:
<div id="clock-container"style="width: 100%">
<div class="col-lg-6" id="clock"></div>
</div>
I added a flipclock countdown timer to my site and I want a way to fire an event every minute so that I can make a change to an element in the source. I tried adding an alert in the code to see if the callback ever gets fired but I am pretty sure I do not quite understand the documentation of the callback method. I referenced the flipclock.min.js and the flipclock.css and I am able to get the clock to countdown and everything i just need to have an event fire after every minute. This is where you can find the documentation and the download: Flipclock.js
This is the javascript code that i currently have:
<script type="text/javascript">
var clock = $('#clock').FlipClock(3600,{
countdown: true,
callbacks: {
_interval: function () {
var time = clock.getTime().time;
alert(time);
if (time % 60 == 0) {
//Change element
}
}
}
});
</script>
Here is the html:
<div id="clock-container"style="width: 100%">
<div class="col-lg-6" id="clock"></div>
</div>
Share
Improve this question
asked Nov 20, 2014 at 3:40
user3788671user3788671
2,0575 gold badges31 silver badges46 bronze badges
1 Answer
Reset to default 5The underscore prefix of your interval callback name is reserved for the global Timer object. In your use case, you should just use "interval". You'll also want to disable the auto start feature, so your clock variable gets assigned to before the first interval callback is called (thus avoiding clock being undefined).
var clock = $('#clock').FlipClock(3600,{
autoStart: false,
countdown: true,
callbacks: {
interval: function () {
var time = clock.getTime().time;
alert(time);
if (time % 60 == 0) {
//Change element
}
}
}
});
clock.start();
本文标签: javascriptFlipclockjs interval callback method that fires an event every minuteStack Overflow
版权声明:本文标题:javascript - Flipclock.js interval callback method that fires an event every minute - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1745193907a2647044.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论