Quick Tip: Make a jQuery Count Up Timer

Gauloran

Kıdemli Moderatör
7 Tem 2013
8,096
585
local
Step 1: Renaming The Old
First you need to grab a copy of the original plugin from the linked article above and extract it somewhere on your hard drive. Now you don't want to have a plugin named count down that counts up do you? We have to rename it. Change the names of the assets/countdown folder and the files inside it to countup respectfully. Also remember to change the paths in index.html that refer to these files.

jquery-countup-timer.jpg



Step 2: Writing The New
Only minor modifications have to be done on the plugin itself. Open assets/countup/jquery.contup.js and do the following edits:

Kod:
// Creating the plugin
$.fn.countup = function(prop){

    var options = $.extend({
        callback    : function(){},
        start       : new Date()    // Changing this to "start"
    },prop);

    // Tename the "left" variable to "passed"
    var passed = 0, d, h, m, s,
        positions;

    init(this, options);

    positions = this.find('.position');

    (function tick(){

        // Calculate the passed time
        passed = Math.floor((new Date() - options.start) / 1000);

        // Calculate the passed minutes, hours and days     

        d = Math.floor(passed / days);
        updateDuo(0, 1, d);
        passed -= d*days;

        h = Math.floor(passed / hours);
        updateDuo(2, 3, h);
        passed -= h*hours;

        m = Math.floor(passed / minutes);
        updateDuo(4, 5, m);
        passed -= m*minutes;

        // Number of seconds passed
        s = passed;
        updateDuo(6, 7, s);

        // Calling an optional user supplied callback
        options.callback(d, h, m, s);

        // Scheduling another call of this function in 1s
        setTimeout(tick, 1000);
    })();

    // This function updates two digit positions at once
    function updateDuo(minor,major,value){
        switchDigit(positions.eq(minor),Math.floor(value/10)%10);
        switchDigit(positions.eq(major),value%10);
    }

    return this;
};
To call the plugin, simply do the following (this is also the code you must place in script.js instead of the current one):

$('#countdown').countup();
Alternatively, if you wish to count up from a moment in the past:

$('#countdown').countup({
    start: new Date(2012, 10, 27, 15, 58, 21) //year, month, day, hour, min, sec
});

this post is quoted​
 
Üst

Turkhackteam.org internet sitesi 5651 sayılı kanun’un 2. maddesinin 1. fıkrasının m) bendi ile aynı kanunun 5. maddesi kapsamında "Yer Sağlayıcı" konumundadır. İçerikler ön onay olmaksızın tamamen kullanıcılar tarafından oluşturulmaktadır. Turkhackteam.org; Yer sağlayıcı olarak, kullanıcılar tarafından oluşturulan içeriği ya da hukuka aykırı paylaşımı kontrol etmekle ya da araştırmakla yükümlü değildir. Türkhackteam saldırı timleri Türk sitelerine hiçbir zararlı faaliyette bulunmaz. Türkhackteam üyelerinin yaptığı bireysel hack faaliyetlerinden Türkhackteam sorumlu değildir. Sitelerinize Türkhackteam ismi kullanılarak hack faaliyetinde bulunulursa, site-sunucu erişim loglarından bu faaliyeti gerçekleştiren ip adresini tespit edip diğer kanıtlarla birlikte savcılığa suç duyurusunda bulununuz.