javascript - Flipclock.js interval callback method that fires an event every minute - Stack Overflow

I added a flipclock countdown timer to my site and I want a way to fire an event every minute so that I

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
Add a ment  | 

1 Answer 1

Reset to default 5

The 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();

发布者:admin,转转请注明出处:http://www.yc00.com/questions/1745193908a4615997.html

相关推荐

发表回复

评论列表(0条)

  • 暂无评论

联系我们

400-800-8888

在线咨询: QQ交谈

邮件:admin@example.com

工作时间:周一至周五,9:30-18:30,节假日休息

关注微信