admin管理员组

文章数量:1311033

I am having trouble getting FlipClock.js to stop after it reaches a specific count. I have tried using the "clock.stop();" call but it doesn't work even after many attempts to set a "stop" number. This is the code I have that works for my counter:

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

    $(document).ready(function() {

        // Instantiate a counter
        clock = new FlipClock($('.clock'), {
            clockFace: 'Counter',
            minimumDigits: 4,
        });

        setTimeout(function() {
            setInterval(function() {
            clock.increment();
        }, 0.1);        
        });             
    });
</script>

Any ideas as to how to set my counter to stop at "300"? Any help is greatly appreciated!

I am having trouble getting FlipClock.js to stop after it reaches a specific count. I have tried using the "clock.stop();" call but it doesn't work even after many attempts to set a "stop" number. This is the code I have that works for my counter:

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

    $(document).ready(function() {

        // Instantiate a counter
        clock = new FlipClock($('.clock'), {
            clockFace: 'Counter',
            minimumDigits: 4,
        });

        setTimeout(function() {
            setInterval(function() {
            clock.increment();
        }, 0.1);        
        });             
    });
</script>

Any ideas as to how to set my counter to stop at "300"? Any help is greatly appreciated!

Share Improve this question edited Jul 31, 2014 at 3:21 Humayun Shabbir 3,2694 gold badges22 silver badges33 bronze badges asked Jul 30, 2014 at 13:59 SproutSprout 651 silver badge6 bronze badges
Add a ment  | 

2 Answers 2

Reset to default 5

EDIT: FlipClock callbacks not being called

There appears to be a bug in the FlipClock callbacks.

Here's an alternative solution (you appear to have a lot of extra code, not sure why, this is a trimmed down version):

    var clock,countup;
    clock = new FlipClock($('h1'), {
        clockFace: 'Counter',
        minimumDigits: 4
    });


    countup = setInterval(function() { 
     if(clock.getTime().time > 300) {
       clock.stop();
       clearInterval(countup);
     }
    },500); 

Check flipclockjs. for the documentation on callbacks.

The following is an example:

        var clock,countup;

        clock = new FlipClock($('.clock'), {
            clockFace: 'Counter',
            minimumDigits: 4,
            callbacks: {
             interval: function() {
               var time = clock.getTime().time;
               if(time > 300) { clearInterval(countup); }
             }
            }
        });

        setTimeout(function() {
         countup = setInterval(function() { clock.increment(); }, 0.1);        
        });     

You rock Adam... This is what worked in the end...

var clock,countup;
        clock = new FlipClock($('.clock'), {
            clockFace: 'Counter',
            minimumDigits: 4,
        });

countup = setInterval(function() {
    clock.increment();
        if(clock.getTime().time > 300) {
        clock.stop();
        clearInterval(countup);
        }     
}, 0);

本文标签: javascriptGetting FlipClockjs to stop after counting up to a numberStack Overflow