Pomoc - Szukaj - Użytkownicy - Kalendarz
Pełna wersja: [JS][HTML] Menu rozwijane
Forum PHP.pl > Forum > Przedszkole
Michasko
No więc na JS nie znam sie prawie wcale, wiec znalazłem taki o to skrypcik (dłuugi :|).
Odpowiada on za wyświetlenie DIV-a po najechaniu na obrazek...

  1. //Pop-it menu- By Dynamic Drive
  2. //For full source code and more DHTML scripts, visit http://www.dynamicdrive.com
  3. //This credit MUST stay intact for use
  4.  
  5. var linkset=new Array()
  6. //SPECIFY MENU SETS AND THEIR LINKS. FOLLOW SYNTAX LAID OUT
  7.  
  8. linkset[0]='<div class="menuitems"><a href="#">Nowości</a></div>'
  9. linkset[0]+='<div class="menuitems"><a href="#">Terminarz wycieczek</a></div>'
  10. linkset[0]+='<div class="menuitems"><a href="#">O naszym klubie</a></div>'
  11.  
  12. linkset[1]='<div class="menuitems"><a href="#">MSNBC</a></div>'
  13. linkset[1]+='<div class="menuitems"><a href="#">CNN</a></div>'
  14. linkset[1]+='<div class="menuitems"><a href="#">ABC News</a></div>'
  15. linkset[1]+='<div class="menuitems"><a href="#">Washington Post</a></div>'
  16.  
  17. ////No need to edit beyond here
  18.  
  19. var ie4=document.all&&navigator.userAgent.indexOf("Opera")==-1
  20. var ns6=document.getElementById&&!document.all
  21. var ns4=document.layers
  22.  
  23. function showmenu(e,which){
  24.  
  25. if (!document.all&&!document.getElementById&&!document.layers)
  26. return
  27.  
  28. clearhidemenu()
  29.  
  30. menuobj=ie4? document.all.popmenu : ns6? document.getElementById("popmenu") : ns4? document.popmenu : ""
  31. menuobj.thestyle=(ie4||ns6)? menuobj.style : menuobj
  32.  
  33. if (ie4||ns6)
  34. menuobj.innerHTML=which
  35. else{
  36. menuobj.document.write('<layer name=gui bgColor=#E6E6E6 width=165 onmouseover="clearhidemenu()" onmouseout="hidemenu()">'+which+'</layer>')
  37. menuobj.document.close()
  38. }
  39.  
  40. menuobj.contentwidth=(ie4||ns6)? menuobj.offsetWidth : menuobj.document.gui.document.width
  41. menuobj.contentheight=(ie4||ns6)? menuobj.offsetHeight : menuobj.document.gui.document.height
  42. eventX=ie4? event.clientX : ns6? e.clientX : e.x
  43. eventY=ie4? event.clientY : ns6? e.clientY : e.y
  44.  
  45. //Find out how close the mouse is to the corner of the window
  46. var rightedge=ie4? document.body.clientWidth-eventX : window.innerWidth-eventX
  47. var bottomedge=ie4? document.body.clientHeight-eventY : window.innerHeight-eventY
  48.  
  49. //if the horizontal distance isn't enough to accomodate the width of the context menu
  50. if (rightedge<menuobj.contentwidth)
  51. //move the horizontal position of the menu to the left by it's width
  52. menuobj.thestyle.left=ie4? document.body.scrollLeft+eventX-menuobj.contentwidth : ns6? window.pageXOffset+eventX-menuobj.contentwidth : eventX-menuobj.contentwidth
  53. else
  54. //position the horizontal position of the menu where the mouse was clicked
  55. menuobj.thestyle.left=ie4? document.body.scrollLeft+eventX : ns6? window.pageXOffset+eventX : eventX
  56.  
  57. //same concept with the vertical position
  58. if (bottomedge<menuobj.contentheight)
  59. menuobj.thestyle.top=ie4? document.body.scrollTop+eventY-menuobj.contentheight : ns6? window.pageYOffset+eventY-menuobj.contentheight : eventY-menuobj.contentheight
  60. else
  61. menuobj.thestyle.top=ie4? document.body.scrollTop+event.clientY : ns6? window.pageYOffset+eventY : eventY
  62. menuobj.thestyle.visibility="visible"
  63. return false
  64. }
  65.  
  66. function contains_ns6(a, b) {
  67. //Determines if 1 element in contained in another- by Brainjar.com
  68. while (b.parentNode)
  69. if ((b = b.parentNode) == a)
  70. return true;
  71. return false;
  72. }
  73.  
  74. function hidemenu(){
  75. if (window.menuobj)
  76. menuobj.thestyle.visibility=(ie4||ns6)? "hidden" : "hide"
  77. }
  78.  
  79. function dynamichide(e){
  80. if (ie4&&!menuobj.contains(e.toElement))
  81. hidemenu()
  82. else if (ns6&&e.currentTarget!= e.relatedTarget&& !contains_ns6(e.currentTarget, e.relatedTarget))
  83. hidemenu()
  84. }
  85.  
  86. function delayhidemenu(){
  87. if (ie4||ns6||ns4)
  88. delayhide=setTimeout("hidemenu()",500)
  89. }
  90.  
  91. function clearhidemenu(){
  92. if (window.delayhide)
  93. clearTimeout(delayhide)
  94. }
  95.  
  96. function highlightmenu(e,state){
  97. if (document.all)
  98. source_el=event.srcElement
  99. else if (document.getElementById)
  100. source_el=e.target
  101. if (source_el.className=="menuitems"){
  102. source_el.id=(state=="on")? "mouseoverstyle" : ""
  103. }
  104. else{
  105. while(source_el.id!="popmenu"){
  106. source_el=document.getElementById? source_el.parentNode : source_el.parentElement
  107. if (source_el.className=="menuitems"){
  108. source_el.id=(state=="on")? "mouseoverstyle" : ""
  109. }
  110. }
  111. }
  112. }
  113.  
  114. if (ie4||ns6)
  115. document.onclick=hidemenu


No i niby działa, ale menu nie pokazuje mi sie przy obrazku, na który najeżdżam, tylko ok. 400px dalej:
http://img45.imageshack.us/img45/4914/yyyyhs7.jpg


Help me, plz! smile.gif

PS. Choć i tak zapewne ten skrypt JS nie ma nic wspólnego z pozycją tego DIV-a...może dostanę jakieś rady? :-)
kossa
Cytat
/if the horizontal distance isn't enough to accomodate the width of the context menu
if (rightedge<menuobj.contentwidth)
//move the horizontal position of the menu to the left by it's width
menuobj.thestyle.left=ie4? document.body.scrollLeft+eventX-menuobj.contentwidth : ns6? window.pageXOffset+eventX-menuobj.contentwidth : eventX-menuobj.contentwidth
else
//position the horizontal position of the menu where the mouse was clicked
menuobj.thestyle.left=ie4? document.body.scrollLeft+eventX : ns6? window.pageXOffset+eventX : eventX


tak na pierwszy rzut oka :-) to tu ustalasz pozycje gdzie ma się warstwa pojawiać ta po najechaniu myszką na menu, być może jeszcze w tym długim kodzie jest jakiś fragment odpowiadający za to, prześledz kod uważnie

Pozdrawiam,
Łukasz
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.