GithubHelp home page GithubHelp logo

libbux / jquery-knob-countdown Goto Github PK

View Code? Open in Web Editor NEW
9.0 9.0 5.0 552 KB

A simple, amazing jQuery countdown timer, visualized with jQuery Knob (aterrien/jQuery-Knob)

JavaScript 91.41% CSS 8.59%

jquery-knob-countdown's People

Contributors

libbux avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar

jquery-knob-countdown's Issues

Support for multiple countdowns on a single page.

As the title says, this does not yet work for multiple countdowns. I 'hacked' myself a way to get this working.
Here's what I did:

(function($) {
    var counters    = [],
        dates       = [],
        counting    = 0;
    $.fn.countdown = function(options) {
        counters[counting] = $(this);
        dates[counting] = options['date'];
        counting++;

        var interval = setInterval(function () { 
            for (var i = counters.length - 1; i >= 0; i--) {
                count_exec(counters[i], dates[i]);
            };
         }, 1000);
    } // End of the main function
    function count_exec(elem, datestring) {
        eventDate = Date.parse(datestring) / 1000; // Parse the date string
        currentDate =   Math.floor($.now() / 1000); // Find the timestamp for now
        seconds = eventDate - currentDate; // Find the number of seconds remaining
        if (seconds <= 0) { // After the event date has passed
            days = 0;
            hours = 0;
            minutes = 0;
            seconds = 0;
        } else {
            days =          Math.floor(seconds / (60 * 60 * 24));       // Divide to find the number of days remaining
            seconds -=      days * 60 * 60 * 24;                        // Subtract the number of (complete, => 24 hours) days calculated above

            hours =         Math.floor(seconds / (60 * 60));            // Get the number of hours from that modified number ^
            seconds -=      hours * 60 * 60;

            minutes =       Math.floor(seconds / 60);
            seconds -=      minutes * 60;
        }
        elem.find('.days').val(days).trigger('change');
        elem.find('.hours').val(hours).trigger('change');
        elem.find('.mins').val(minutes).trigger('change');
        elem.find('.secs').val(seconds).trigger('change');
    }
}) (jQuery);

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.