Witaj Gościu! ( Zaloguj | Rejestruj )

Forum PHP.pl

> [JavaScript]Odliczanie czasu
Randallmaster
post
Post #1





Grupa: Zarejestrowani
Postów: 677
Pomógł: 11
Dołączył: 18.11.2009

Ostrzeżenie: (0%)
-----


Jak dodać do set interval date oraz callback, potrzebuję osiągnąć odliczanie z przekazaną datą.

  1. var now = new Date(timeServer['year'], timeServer['month'], timeServer['day'], timeServer['hour'], timeServer['minute'] ,timeServer['second'], 00);
  2. interval[id] = window.setInterval(function(){
  3. //tu muszę mieć parametr now, oraz callback
  4. }
Go to the top of the page
+Quote Post
 
Start new topic
Odpowiedzi
Comandeer
post
Post #2





Grupa: Zarejestrowani
Postów: 1 268
Pomógł: 254
Dołączył: 11.06.2009
Skąd: Świętochłowice

Ostrzeżenie: (0%)
-----


Ok, kombinowałem w ciut inną stronę.
Kod
<script>
    var timeServer = {
        year: <?=date('Y');?>
        ,month: <?=date('m');?>
        ,day: <?=date('d');?>
        ,hour: <?=date('H');?>
        ,minute: <?=date('i');?>
        ,second: <?=date('s');?>
    }
    ,interval
    ,paused
    ,changeTime = function(i)
    {
        i = i || 1;

        now.setSeconds(now.getSeconds() + i);

        console.log(now);
    }
    ,now = new Date(timeServer['year'], timeServer['month'], timeServer['day'], timeServer['hour'], timeServer['minute'] ,timeServer['second'], 00); //aktualny czas pobrany z serwera


    interval = setInterval(changeTime, 1000);

    document.addEventListener('visibilitychange', function()
    {

        if(document.hidden)
        {
            clearInterval(interval);
            paused = Date.now();
        }
        else
        {
            changeTime(Math.floor((Date.now() - paused) / 1000));

            interval = setInterval(changeTime, 1000);
        }

        console.log('visibilitychange', now);
    }, false);
</script>
Go to the top of the page
+Quote Post

Posty w temacie


Reply to this topicStart new topic
2 Użytkowników czyta ten temat (2 Gości i 0 Anonimowych użytkowników)
0 Zarejestrowanych:

 



RSS Aktualny czas: 13.10.2025 - 14:58