Pomoc - Szukaj - Użytkownicy - Kalendarz
Pełna wersja: Mam troche smieszny problem z menu - rollover
Forum PHP.pl > Forum > Po stronie przeglądarki
B3T0N
oto kawalek menu :

  1. <div id="masterdiv">
  2.  
  3. <div class="menutitle" onclick="SwitchMenu('sub1')">OBUDOWY</div>
  4. <span class="submenu" id="sub1">
  5. <table width="190" border="0" cellspacing="0" cellpadding="0" class="czciona">
  6.  
  7.  
  8. <?php
  9. $query = "SELECT id_kategorii, nazwa_kategorii, rodzic FROM kategorie WHERE rodzic='25';";
  10. $result = mysql_query($query) or die("zapytanie: '$query' zakonczone niepowodzeniem");
  11. while ($i = mysql_fetch_row($result)) {
  12.  
  13. ?>
  14.  
  15. <tr>
  16. <td height="19" background="images/menu/tlopodmenu.gif">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <a href="index.php?action=szukanieWynik&IDKategorii=<?php echo $i[0] ?>"><?php echo $i[1]?> </a>
  17. <?php //listowanie ilosci w danej kategorii i drukowanie linka z nazwa kategorii i ilosciaw niej
  18. $query = "SELECT COUNT(*) FROM stuff WHERE id_kategorii='$i[0]';";
  19. $result2 = mysql_query($query) or die("zapytanie: '$query' zakonczone niepowodzeniem");
  20. $ilosc = mysql_fetch_row($result2);
  21. ?> <strong>(<? echo $ilosc[0] ?>)</strong> </td>
  22. </tr>
  23.  
  24.  
  25.  
  26.  
  27. <? } ?>
  28.  
  29. </table>


jest tam tabela z " background="images/menu/tlopodmenu.gif"> "

chcialbym , aby po kliknieciu zmienialo mi background tej tabeli na inny -


LUB

aby po kliknieciu nakladalo w jakis sposob inny kolor (przezroczysty)


wydaje sie banalne, bo widac ze pisze w php ,ale JS dla mnie jest ze tak powiem jeszcze w statum bardzo poczatkujacym (jak nie zerowym) , dlatego prosze o pomoc

z gory dzieki i pozdro
revyag
A po kliknięciu w co ? W tego diva ? Tam już masz przypisaną jakąś funkcję.
B3T0N
w div'a nie - div jest nadrzedny

w to

  1. <tr>
  2. <td height="19" background="images/menu/tlopodmenu.gif">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <a href="index.php?action=szukanieWynik&IDKategorii=<?php echo $i[0] ?>"><?php echo $i[1]?> </a>
  3. <?php //listowanie ilosci w danej kategorii i drukowanie linka z nazwa kategorii i ilosciaw niej $query = "SELECT COUNT(*) FROM stuff WHERE id_kategorii='$i[0]';";
  4. $result2 = mysql_query($query) or die("zapytanie: '$query' zakonczone niepowodzeniem");
  5. $ilosc = mysql_fetch_row($result2);
  6. ?> <strong>(<? echo $ilosc[0] ?>)</strong> </td>
  7. </tr>
  8.  
  9.  
  10.  
  11.  
  12. <? } ?>


pozdrawiam
revyag
Najpierw prościutka funkcja w js:
Kod
<script type="text/javascript">
function sw(t){
    document.getElementById(t).style.backgroundImage="url(images/menu/obrazek.gif)";
}
</script

Lekka modyfikacja komórki:
  1. <td id="tt" height="19" style="background-image:url(images/menu/tlopodmenu.gif)">
  2. <a href="index.php?action=szukanieWynik&IDKategorii=<?php echo $i[0] ?>" onclick="sw('tt')"><?php echo $i[1]?> </a>
  3. ....
  4. </td>
B3T0N
oki , dziala mi to smile.gif dziekuje bardzo smile.gif

mam jeszcze jedno pytanie , poniewaz to menu opiera sie na cookies (jest to menu z dynamicdrive.com

w jaki sposob kazac mu zapamietac , ze gdy sie kliknie , to sie zmieni image ?


kod calego skryptu :

  1. <script type="text/javascript">
  2. <!--
  3. /***********************************************
  4. * Switch Menu script- by Martial B of http://getElementById.com/
  5. * Modified by Dynamic Drive for format & NS4/IE4 compatibility
  6. * Visit http://www.dynamicdrive.com/ for full source code
  7. ***********************************************/
  8.  
  9. var persistmenu="yes" //"yes" or "no". Make sure each SPAN content contains an incrementing ID starting at 1 (id="sub1", id="sub2", etc)
  10. var persisttype="sitewide" //enter "sitewide" for menu to persist across site, "local" for this page only
  11.  
  12. if (document.getElementById){ //DynamicDrive.com change
  13. document.write('<style type="text/css">\n')
  14. document.write('.submenu{display: none;}\n')
  15. document.write('</style>\n')
  16. }
  17.  
  18. function SwitchMenu(obj){
  19. if(document.getElementById){
  20. var el = document.getElementById(obj);
  21. var ar = document.getElementById("masterdiv").getElementsByTagName("span"); //DynamicDrive.com change
  22. if(el.style.display != "block"){ //DynamicDrive.com change
  23. for (var i=0; i<ar.length; i++){
  24. if (ar[i].className=="submenu") //DynamicDrive.com change
  25. ar[i].style.display = "none";
  26. }
  27. el.style.display = "block";
  28. }else{
  29. el.style.display = "none";
  30. }
  31. }
  32. }
  33.  
  34. function get_cookie(Name) {
  35. var search = Name + "="
  36. var returnvalue = "";
  37. if (document.cookie.length > 0) {
  38. offset = document.cookie.indexOf(search)
  39. if (offset != -1) {
  40. offset += search.length
  41. end = document.cookie.indexOf(";", offset);
  42. if (end == -1) end = document.cookie.length;
  43. returnvalue=unescape(document.cookie.substring(offset, end))
  44. }
  45. }
  46. return returnvalue;
  47. }
  48.  
  49. function onloadfunction(){
  50. if (persistmenu=="yes"){
  51. var cookiename=(persisttype=="sitewide")? "switchmenu" : window.location.pathname
  52. var cookievalue=get_cookie(cookiename)
  53. if (cookievalue!="")
  54. document.getElementById(cookievalue).style.display="block"
  55. }
  56. }
  57.  
  58. function savemenustate(){
  59. var inc=1, blockid=""
  60. while (document.getElementById("sub"+inc)){
  61. if (document.getElementById("sub"+inc).style.display=="block"){
  62. blockid="sub"+inc
  63. break
  64. }
  65. inc++
  66. }
  67. var cookiename=(persisttype=="sitewide")? "switchmenu" : window.location.pathname
  68. var cookievalue=(persisttype=="sitewide")? blockid+";path=/" : blockid
  69. document.cookie=cookiename+"="+cookievalue
  70. }
  71.  
  72. if (window.addEventListener)
  73. window.addEventListener("load", onloadfunction, false)
  74. else if (window.attachEvent)
  75. window.attachEvent("onload", onloadfunction)
  76. else if (document.getElementById)
  77. window.onload=onloadfunction
  78.  
  79. if (persistmenu=="yes" && document.getElementById)
  80. window.onunload=savemenustate
  81.  
  82. function MM_preloadImages() { //v3.0
  83. var d=document; if(d.images){ if(!d.MM_p) d.MM_p=new Array();
  84. var i,j=d.MM_p.length,a=MM_preloadImages.arguments; for(i=0; i<a.length; i++)
  85. if (a[i].indexOf("#")!=0){ d.MM_p[j]=new Image; d.MM_p[j++].src=a[i];}}
  86. }
  87.  
  88. function MM_findObj(n, d) { //v4.01
  89. var p,i,x; if(!d) d=document; if((p=n.indexOf("?"))>0&&parent.frames.length) {
  90. d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);}
  91. if(!(x=d[n])&&d.all) x=d.all[n]; for (i=0;!x&&i<d.forms.length;i++) x=d.forms[i][n];
  92. for(i=0;!x&&d.layers&&i<d.layers.length;i++) x=MM_findObj(n,d.layers[i].document);
  93. if(!x && d.getElementById) x=d.getElementById(n); return x;
  94. }
  95.  
  96. function MM_nbGroup(event, grpName) { //v6.0
  97. var i,img,nbArr,args=MM_nbGroup.arguments;
  98. if (event == "init" && args.length > 2) {
  99. if ((img = MM_findObj(args[2])) != null && !img.MM_init) {
  100. img.MM_init = true; img.MM_up = args[3]; img.MM_dn = img.src;
  101. if ((nbArr = document[grpName]) == null) nbArr = document[grpName] = new Array();
  102. nbArr[nbArr.length] = img;
  103. for (i=4; i < args.length-1; i+=2) if ((img = MM_findObj(args[i])) != null) {
  104. if (!img.MM_up) img.MM_up = img.src;
  105. img.src = img.MM_dn = args[i+1];
  106. nbArr[nbArr.length] = img;
  107. } }
  108. } else if (event == "over") {
  109. document.MM_nbOver = nbArr = new Array();
  110. for (i=1; i < args.length-1; i+=3) if ((img = MM_findObj(args[i])) != null) {
  111. if (!img.MM_up) img.MM_up = img.src;
  112. img.src = (img.MM_dn && args[i+2]) ? args[i+2] : ((args[i+1])? args[i+1] : img.MM_up);
  113. nbArr[nbArr.length] = img;
  114. }
  115. } else if (event == "out" ) {
  116. for (i=0; i < document.MM_nbOver.length; i++) {
  117. img = document.MM_nbOver[i]; img.src = (img.MM_dn) ? img.MM_dn : img.MM_up; }
  118. } else if (event == "down") {
  119. nbArr = document[grpName];
  120. if (nbArr)
  121. for (i=0; i < nbArr.length; i++) { img=nbArr[i]; img.src = img.MM_up; img.MM_dn = 0; }
  122. document[grpName] = nbArr = new Array();
  123. for (i=2; i < args.length-1; i+=2) if ((img = MM_findObj(args[i])) != null) {
  124. if (!img.MM_up) img.MM_up = img.src;
  125. img.src = img.MM_dn = (args[i+1])? args[i+1] : img.MM_up;
  126. nbArr[nbArr.length] = img;
  127. } }
  128. }
  129. function sw(t){
  130. document.getElementById(t).style.backgroundImage="url(images/menu/tlo.gif)";
  131. }
  132.  
  133. //-->
revyag
A co chcesz z tym zapamiętanym obrazkiem zrobić ? Może jest prostszy sposób na to co chcesz osiągnąć niż korzystanie z cookie.
B3T0N
chodzi mi dokladniej o to, aby zapamietal stan obrazka po kliknieciu - przy odswiezaniu strony np.
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.