Witaj Gościu! ( Zaloguj | Rejestruj )

Forum PHP.pl

 
Reply to this topicStart new topic
> Dynamiczna zmiana koloru kwadratu
Mixter78
post
Post #1





Grupa: Zarejestrowani
Postów: 34
Pomógł: 0
Dołączył: 17.10.2013

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


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ć?
Go to the top of the page
+Quote Post
Damonsson
post
Post #2





Grupa: Zarejestrowani
Postów: 2 355
Pomógł: 533
Dołączył: 15.01.2010
Skąd: Bydgoszcz

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


[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

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: 25.08.2025 - 06:45