Witaj Gościu! ( Zaloguj | Rejestruj )

Forum PHP.pl

> [HTML][JavaScript]Zmiana obrazków po upływie czasu
--miras666--
post
Post #1





Goście







Witam. Na stronie znajdują się dwa obrazki. Aktualnie, po upływie 1 sekundy obrazek "1.jpg" zmienia się na "2.jpg". Chciałbym dodać możliwość, aby także drugi plik zmieniał się na inny ("3.jpg" na "4.jpg"). Jednak nie wiem jak się za to wziąć. Z góry dziękuję.
  1. <meta http-equiv="content-type" content="text/html; charset=ISO-8859-2">
  2.  
  3. <script type="text/javascript">
  4. setTimeout ( "ZmianaObrazka()", 1000 );
  5. function ZmianaObrazka ( )
  6. {
  7.  
  8. if(document.getElementById("imgid").src="1.jpg") {
  9. document.getElementById("imgid").src="2.jpg";
  10. setTimeout ( "ZmianaObrazka()", 1000 );
  11.  
  12.  
  13. }
  14. }
  15.  
  16.  
  17.  
  18. <img src="1.jpg" id="imgid" />
  19. <br>
  20. <img src="3.jpg" id="imgid" />
  21.  
  22. </body></html>
Go to the top of the page
+Quote Post
 
Start new topic
Odpowiedzi (1 - 3)
Mega_88
post
Post #2





Grupa: Zarejestrowani
Postów: 360
Pomógł: 34
Dołączył: 20.08.2011

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


Nadaj inne id dla obrazka 3 i powtórz funkcję zmiany dla obrazka 3 na 4

  1. <script type="text/javascript">
  2. setTimeout ( "ZmianaObrazka()", 1000 );
  3. function ZmianaObrazka ( )
  4. {
  5. if(document.getElementById("imgid_druga").src="3.jpg") {
  6. document.getElementById("imgid_druga").src="4.jpg";
  7. setTimeout ( "ZmianaObrazka()", 1000 );
  8. }
  9. }
  10. <img src="3.jpg" id="imgid_druga" />


Możesz też to zrobić w jednej funkcji.

Ten post edytował Mega_88 9.05.2013, 21:04:29
Go to the top of the page
+Quote Post
--miras666--
post
Post #3





Goście







Coś takiego działa. Dzięki wielkie
  1. <meta http-equiv="content-type" content="text/html; charset=ISO-8859-2">
  2.  
  3. <script type="text/javascript">
  4. setTimeout ( "ZmianaObrazka()", 1000 );
  5. function ZmianaObrazka ( )
  6. {
  7.  
  8. if(document.getElementById("imgid").src="1.jpg") {
  9. document.getElementById("imgid").src="2.jpg";
  10. setTimeout ( "ZmianaObrazka()", 1000 );
  11.  
  12.  
  13. }
  14. }
  15. setTimeout ( "ZmianaObrazka2()", 1000 );
  16. function ZmianaObrazka2 ( )
  17. {
  18.  
  19. if(document.getElementById("imgid_druga").src="3.jpg") {
  20. document.getElementById("imgid_druga").src="4.jpg";
  21. setTimeout ( "ZmianaObrazka()", 1000 );
  22.  
  23.  
  24. }
  25. }
  26.  
  27.  
  28.  
  29.  
  30. <img src="1.jpg" id="imgid" />
  31. <br>
  32. <img src="3.jpg" id="imgid_druga" />
  33.  
  34.  
  35.  
  36. </body></html>
Go to the top of the page
+Quote Post
Mega_88
post
Post #4





Grupa: Zarejestrowani
Postów: 360
Pomógł: 34
Dołączył: 20.08.2011

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


Powodzenia dalej (IMG:style_emoticons/default/smile.gif)
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: 19.09.2025 - 19:31