Search code examples
javascriptflipclock

Duplicate flipclock


Im using Flipclock for my website, my question is... How do I put more then 1 flipclock in a page?

If I try to duplicate them it doesnt work (As in copy paste the div tags and just rename them)

Any idea how to put more then 1 flipclock in a webpage?

http://flipclockjs.com/

This is what I get : http://i58.tinypic.com/k3xk0p.png

This is my code :

    <asp:Content ID="Content1" ContentPlaceHolderID="head" Runat="Server">
        <link rel="stylesheet" href="../includes/flipclock.css" />

        <script src="http://ajax.googleapis.com/ajax/libs/jquery/1.10.2/jquery.min.js"></script>

        <script src="../includes/flipclock.js"></script>
    <script type="text/javascript">
        var clock;

        $(document).ready(function () {
            var clock;

            clock = $('.clock').FlipClock({
                clockFace: 'DailyCounter',
                autoStart: false,
                callbacks: {
                    stop: function () {
                        $('.message').html('The clock has stopped!')
                    }
                }
            });

            clock.setTime(65000); /*60 = 1 Minute*/
            clock.setCountdown(true);
            clock.start();

        });
    </script>
        <style type="text/css">
        section
        {
            background-color:rgba(0, 0, 0, 0.45);
            width:900px;
            padding-top:5px;
            margin-left:10px;
            border:1px solid rgb(16, 16, 16);
        }   
        footer
        {
            position:relative;
            top:25px;
        }         
    </style>
</asp:Content>

<asp:Content ID="Content2" ContentPlaceHolderID="mainContent" Runat="Server">
    <div class="clock" style="margin:2em;"></div>
    <div class="message"></div>
    <div class="clock" style="margin:2em;"></div>
    <div class="message"></div>
    </asp:Content>

Solution

  • Initialize a new instance of FlipClock, maybe that'll do the trick. And choose different class names:

    <div class="clockTwo" style="margin:2em;"></div>
    

    And the JS:

    clockTwo = $('.clockTwo').FlipClock({
                clockFace: 'DailyCounter',
                autoStart: false,
                callbacks: {
                    stop: function () {
                        $('.message').html('The clock has stopped!')
                    }
                }
            });