Pomoc - Szukaj - Użytkownicy - Kalendarz
Pełna wersja: Dynamiczna zmiana koloru kwadratu
Forum PHP.pl > Forum > Po stronie przeglądarki > JavaScript
Mixter78
Witam, mam pewien problem.

Posiadam 3 kwadraty
  1. <div id="1" style="margin:1%;background:pink;width:100px;height:100px;float:left;">
  2. </div>
  3. <div id="2" style="margin:1%;background:pink;width:100px;height:100px;float:left;"></div>
  4. <div id="3" style="margin:1%;background:pink;width:100px;height:100px;float:left;"></div>


oraz 2 divy "sterujące"
  1. <div id="left" onClick="left()" style="margin:1%;background:blue;width:50px;height:50px;float:left;">left</div>
  2. <div id="right" onClick="right()" style="margin:1%;background:blue;width:50px;height:50px;float:left;">right</div>


w Javascript koloruje jeden kwadrat
var id = "'.rand(1,3).'";
document.getElementById(id).style.background = "red";


I nie wiem jak zrobić, by po liknięciu w odpowiedni "div sterujący" kolor kwadratu "przeszedł" na kwadrat sąsiedni :/
Ktoś wie jak to zrobić?
Damonsson
[JAVASCRIPT] pobierz, plaintext
  1. var id = "'.rand(1,3).'";
  2. document.getElementById(id).style.background = "red";
  3. var change = 1;
  4.  
  5. function left() {
  6. var newid = id - change;
  7. document.getElementById(newid).style.background = "red";
  8. document.getElementById(id).style.background = "pink";
  9. id = newid;
  10. }
  11.  
  12. function right() {
  13. var newid = id + change;
  14. document.getElementById(newid).style.background = "red";
  15. document.getElementById(id).style.background = "pink";
  16. id = newid;
  17. }
[JAVASCRIPT] pobierz, plaintext

To jest wersja lo-fi głównej zawartości. Aby zobaczyć pełną wersję z większą zawartością, obrazkami i formatowaniem proszę kliknij tutaj.
Invision Power Board © 2001-2025 Invision Power Services, Inc.