Witaj Gościu! ( Zaloguj | Rejestruj )

Forum PHP.pl

> [JS] Timer zatrzymuje się na 0.1
Dominator
post
Post #1





Grupa: Zarejestrowani
Postów: 565
Pomógł: 15
Dołączył: 11.10.2010

Ostrzeżenie: (20%)
X----


Jak w temacie, dlaczego?

  1. <html>
  2. <head>
  3. <script type="text/javascript" src="http://code.jquery.com/jquery-1.9.1.min.js"></script>
  4. <script type="text/javascript">
  5. $(document).ready(function()
  6. {
  7. var milisec=0;
  8. var seconds=0;
  9. function display()
  10. {
  11. if (milisec>=9)
  12. {
  13. milisec=0;
  14. seconds+=1;
  15. }
  16. else
  17. {
  18. milisec+=1;
  19. setInterval("display()",100);
  20. $("div[id='timer']").text(seconds+"."+milisec);
  21. }
  22. }
  23. display();
  24. });
  25. </script>
  26. </head>
  27. <body>
  28. <div id="timer"></div>
  29. </body>
  30. </html>
Go to the top of the page
+Quote Post
 
Start new topic
Odpowiedzi
lukasz1985
post
Post #2





Grupa: Zarejestrowani
Postów: 205
Pomógł: 43
Dołączył: 5.03.2012

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


  1. <!--
  2. To change this template, choose Tools | Templates
  3. and open the template in the editor.
  4. -->
  5. <!DOCTYPE html>
  6. <head>
  7. <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
  8. </head>
  9. <body>
  10. <div>TODO write content</div>
  11.  
  12.  
  13. <script type="text/javascript" >
  14.  
  15. window.onload = function()
  16. {
  17. var time = 0;
  18. function display(){
  19. time += 0.1
  20.  
  21. seconds = Math.floor(time );
  22. milisec = Math.floor(( time *10 ) % 10 );
  23. document.getElementById("timer").innerHTML = seconds+"."+milisec;
  24. }
  25.  
  26. setInterval(display, 100);
  27. };
  28. </script>
  29.  
  30. <div id="timer">
  31.  
  32. </div>
  33. </body>
  34. </html>
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: 6.10.2025 - 23:34