Witaj Gościu! ( Zaloguj | Rejestruj )

Forum PHP.pl

 
Reply to this topicStart new topic
> [HTML][JavaScript]Gwiazdki do oceniania
zavada
post
Post #1





Grupa: Zarejestrowani
Postów: 68
Pomógł: 6
Dołączył: 15.06.2009
Skąd: Kraków

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


Witam!
Mam trzy pliki: star.png, star_grey.png i star_bronze.png
Chcę zrobić system oceniania. Z php i mysql nie mam problemu, ale jak zrobić najeżdżanie na gwiazdki? To znaczy średnia ocen to 3/5. Więc skrypt pisze kod:

  1. <img src="star_bronze.png">
  2. <img src="star_bronze.png">
  3. <img src="star_bronze.png">
  4. <img src="star_grey.png">
  5. <img src="star_grey.png">


Ale jak zrobić to, że jak najadę na 2. gwiazdkę to wygląda tak:
  1. <img src="star_gold.png">
  2. <img src="star_gold.png">
  3. <img src="star_bronze.png">
  4. <img src="star_grey.png">
  5. <img src="star_grey.png">


A jak najadę na 4. to wygląda tak:?
  1. <img src="star_gold.png">
  2. <img src="star_gold.png">
  3. <img src="star_gold.png">
  4. <img src="star_gold.png">
  5. <img src="star_grey.png">


Wiem, wiem. Jest dużo takich tematów, ale w żadnym nie znalazłem tego, co chcę.
Go to the top of the page
+Quote Post
kefirek
post
Post #2





Grupa: Zarejestrowani
Postów: 781
Pomógł: 256
Dołączył: 29.06.2008

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


http://masugadesign.com/the-lab/scripts/un...tar-rating-bar/
Go to the top of the page
+Quote Post
zavada
post
Post #3





Grupa: Zarejestrowani
Postów: 68
Pomógł: 6
Dołączył: 15.06.2009
Skąd: Kraków

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


A coś prostszego (jakieś onmouseover i javascript) ?

  1. <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Strict//EN">
  2. <meta content="text/html; charset=WINDOWS-1250" http-equiv="content-type">
  3. <title>Gwiazdki</title>
  4. <script type="text/javascript">
  5. function Rate(type, starNumber) {
  6. for (i = 1; i <= starNumber; i++) {
  7. if (type == 'over') {
  8. if (i <= rate) {
  9. starId = document.getElementById ("star" + i);
  10. starId.src = 'star.png';
  11. }
  12. else {
  13. starId = document.getElementById ("star" + i);
  14. starId.src = 'star.png';
  15. }
  16. }
  17. else if (type == 'out') {
  18. if (i <= rate) {
  19. starId = document.getElementById ("star" + i);
  20. starId.src = 'star_bronze.png';
  21. }
  22. else {
  23. starId = document.getElementById ("star" + i);
  24. starId.src = 'star_grey.png';
  25. }
  26. }
  27. }
  28. }
  29. </script>
  30. </head>
  31. <script type="text/javascript">
  32. rate = 3;
  33. for (i = 1; i <= rate; i++) {
  34. starId = document.getElementById ("star" + i);
  35. starId.src = 'star_bronze.png';
  36. }
  37. <img src="star_grey.png" id="star1" onmouseover="Rate('over', 1)" onmouseout="Rate('out', 1)">
  38. <img src="star_grey.png" id="star2" onmouseover="Rate('over', 2)" onmouseout="Rate('out', 2)">
  39. <img src="star_grey.png" id="star3" onmouseover="Rate('over', 3)" onmouseout="Rate('out', 3)">
  40. <img src="star_grey.png" id="star4" onmouseover="Rate('over', 4)" onmouseout="Rate('out', 4)">
  41. <img src="star_grey.png" id="star5" onmouseover="Rate('over', 5)" onmouseout="Rate('out', 5)">
  42. </body>
  43. </html>


Mam coś takiego. problem w tym, że jak urucchomie skrypt to musze najechać na gwiazdki, zeby zmieniły się na star_bronze.png
Jak zrobć, zeby bylo od razu
Go to the top of the page
+Quote Post
Pawel_W
post
Post #4





Grupa: Zarejestrowani
Postów: 1 675
Pomógł: 286
Dołączył: 15.06.2009
Skąd: Wieliczka

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


body onload?

EDIT: skrypt masz poprawny, jedyne co to tutaj jest błąd
  1. <script type="text/javascript">
  2. rate = 3;
  3. for (i = 1; i <= rate; i++) {
  4. starId = document.getElementById ("star" + i);
  5. starId.src = 'star_bronze.png';
  6. }
  7. <img src="star_grey.png" id="star1" onmouseover="Rate('over', 1)" onmouseout="Rate('out', 1)">
  8. <img src="star_grey.png" id="star2" onmouseover="Rate('over', 2)" onmouseout="Rate('out', 2)">
  9. <img src="star_grey.png" id="star3" onmouseover="Rate('over', 3)" onmouseout="Rate('out', 3)">
  10. <img src="star_grey.png" id="star4" onmouseover="Rate('over', 4)" onmouseout="Rate('out', 4)">
  11. <img src="star_grey.png" id="star5" onmouseover="Rate('over', 5)" onmouseout="Rate('out', 5)">

pętla zmienia ci gwiazdki na brązowe, ale te obrazki nie istnieją, zamień to na:
  1. <img src="star_grey.png" id="star1" onmouseover="Rate('over', 1)" onmouseout="Rate('out', 1)">
  2. <img src="star_grey.png" id="star2" onmouseover="Rate('over', 2)" onmouseout="Rate('out', 2)">
  3. <img src="star_grey.png" id="star3" onmouseover="Rate('over', 3)" onmouseout="Rate('out', 3)">
  4. <img src="star_grey.png" id="star4" onmouseover="Rate('over', 4)" onmouseout="Rate('out', 4)">
  5. <img src="star_grey.png" id="star5" onmouseover="Rate('over', 5)" onmouseout="Rate('out', 5)">
  6. <script type="text/javascript">
  7. rate = 3;
  8. for (i = 1; i <= rate; i++) {
  9. starId = document.getElementById ("star" + i);
  10. starId.src = 'star_bronze.png';
  11. }


Ten post edytował Pawel_W 20.07.2009, 19:51:56
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: 23.08.2025 - 05:17