Witaj Gościu! ( Zaloguj | Rejestruj )

Forum PHP.pl

> [js]funkcja która sam asie wykonuje
pys1986
post
Post #1





Grupa: Zarejestrowani
Postów: 233
Pomógł: 0
Dołączył: 18.01.2005

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


jak powinna wyglądać funkcja która bedzie się wykonywała sama co np 2 sekundy (IMG:http://forum.php.pl/style_emoticons/default/questionmark.gif)
Go to the top of the page
+Quote Post
 
Start new topic
Odpowiedzi (1 - 7)
sticker
post
Post #2





Grupa: Zarejestrowani
Postów: 611
Pomógł: 19
Dołączył: 28.02.2005
Skąd: Wrocław

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


  1. function a(){
  2. //zrob cos tam
  3. setTimeout(a(),2000);
  4. }
  5. setTimeout(a(),2000);
Go to the top of the page
+Quote Post
phpion
post
Post #3





Grupa: Moderatorzy
Postów: 6 072
Pomógł: 861
Dołączył: 10.12.2003
Skąd: Dąbrowa Górnicza




@sticker - obawiam się, że Twój kod nie zabangla... (IMG:http://forum.php.pl/style_emoticons/default/winksmiley.jpg) powinno być tak:
  1. setTimeout("a()",2000);
Go to the top of the page
+Quote Post
pys1986
post
Post #4





Grupa: Zarejestrowani
Postów: 233
Pomógł: 0
Dołączył: 18.01.2005

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


  1. <style type="text/css">
  2. #d2 {
  3. background: orange;
  4. display: none;
  5. }
  6. #d3 {
  7. background: red;
  8. display: block;
  9. }
  10. </style>
  11. </head>
  12.  
  13. <script type="text/javascript">
  14.  
  15. function zmien() {
  16. el = document.getElementById("d2");
  17. e2 = document.getElementById("d3");
  18. if (el.style.display == "block") {
  19. el.style.display = "none";
  20. e2.style.display = "block";
  21. } else {
  22. el.style.display = "block";
  23. e2.style.display = "none";
  24. }
  25. }
  26.  
  27.  
  28. setTimeout("zmien()",2000);
  29.  
  30.  
  31. </script>
  32.  
  33. <div id="d2">b</div>
  34. <div id="d3">c</div>
  35.  
  36.  
  37. </body>
  38. </html>


w JS jestem słaby ale zrobiłem coś takiego i wykonuje mi sie to tylko raz a chciałbym aby sie wykonywało w "kółko" i chciałbym też zrobić przycisk który byłby w stanie to zatrzymać (IMG:http://forum.php.pl/style_emoticons/default/sad.gif)
Go to the top of the page
+Quote Post
slammer
post
Post #5





Grupa: Zarejestrowani
Postów: 187
Pomógł: 6
Dołączył: 31.08.2005
Skąd: Bielsko-Biała

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


  1. <style type="text/css">
  2. #d2 {
  3. background: orange;
  4. display: none;
  5. }
  6. #d3 {
  7. background: red;
  8. display: block;
  9. }
  10. </head>
  11.  
  12. <script type="text/javascript">
  13.  
  14. function zmien() {
  15. el = document.getElementById("d2");
  16. e2 = document.getElementById("d3");
  17. if (el.style.display == "block") {
  18. el.style.display = "none";
  19. e2.style.display = "block";
  20. } else {
  21. el.style.display = "block";
  22. e2.style.display = "none";
  23. }
  24. }
  25.  
  26.  
  27. var uchwyt = setInterval("zmien()",2000);
  28.  
  29.  
  30.  
  31. <div id="d2">b</div>
  32. <div id="d3">c</div>
  33. <input type="button" value="zatrzymaj" onclick="clearInterval(uchwyt);" />
  34.  
  35.  
  36. </body>
  37. </html>
Go to the top of the page
+Quote Post
pys1986
post
Post #6





Grupa: Zarejestrowani
Postów: 233
Pomógł: 0
Dołączył: 18.01.2005

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


super (IMG:http://forum.php.pl/style_emoticons/default/smile.gif) o to mi chodziło (IMG:http://forum.php.pl/style_emoticons/default/smile.gif) a mam jeszcze ostatnie pytanie jaka pownna być użyta funkcja aby to uruchomić z powrotem przyciskiem.


edit: poradziłem sobie dodając
  1. <input type="button" value="wznów" onclick="setInterval('zmien()',500);" />

tylko jest problem że jak sie kilka razy wciśnie ten button to sie zaczyna sypac (IMG:http://forum.php.pl/style_emoticons/default/sad.gif)

Ten post edytował pys1986 30.11.2007, 17:48:34
Go to the top of the page
+Quote Post
saq84
post
Post #7





Grupa: Zarejestrowani
Postów: 5
Pomógł: 0
Dołączył: 29.11.2007
Skąd: Kraków

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


powinno byc np.

zatrzymanie:
  1. <input type="button" value="zatrzymaj" onclick="clearInterval(uchwyt);uchwyt=null;return false;" />


wznowienie:
  1. <input type="button" value="wznów" onclick="if (!uchwyt) uchwyt=setInterval('zmien()',500);return false;" />
Go to the top of the page
+Quote Post
pys1986
post
Post #8





Grupa: Zarejestrowani
Postów: 233
Pomógł: 0
Dołączył: 18.01.2005

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


Dzieki o to mi chodziło
Go to the top of the page
+Quote Post

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: 22.12.2025 - 19:57