Witaj Gościu! ( Zaloguj | Rejestruj )

Forum PHP.pl

> Chowanie się menu
daris
post
Post #1





Grupa: Zarejestrowani
Postów: 78
Pomógł: 4
Dołączył: 7.01.2008

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


Próbuje zrobić menu, ale  mam jeden problem, a dokładniej nie wiem jak zrobić jedną rzecz. Chodzi o ten fragment:

Kod
el.onmouseout = function(e){
     document.body.removeChild(menu);
 }



Teraz menu chowa się wtedy kiedy kursor będzie poza linkiem, a jak to przerobić żeby się chowało wtedy kiedy kursor będzie poza linkiem i poza div'em menu?

  1. <script type="text/javascript">
  2.  
  3. function menu(el, m){
  4.  var menu = document.createElement("div");
  5.  xpos = findPos(el)[0];
  6.  ypos = findPos(el)[1] + el.offsetHeight;
  7.  
  8.  menu.style = 'background: lime; border: 1px solid green; position:absolute; top:' + ypos + 'px; left: ' + xpos + 'px';
  9.  
  10.  if (m == 1)
  11.   menu.innerHTML = '<ul><li><a href="profile">Profil</a></li></ul>';
  12.  else if (m == 2)
  13.   menu.innerHTML = '<ul><li><a href="settings">Ustawienia</a></li></ul>';
  14.  
  15.  document.body.appendChild(menu);
  16.  
  17.  el.onmouseout = function(e){
  18.   document.body.removeChild(menu);
  19.  }
  20. }
  21.  
  22. function findPos(obj) {
  23.   var nleft = 0;
  24.   var ntop = 0;
  25.   if (obj.offsetParent) {
  26.   nleft = obj.offsetLeft
  27.   ntop = obj.offsetTop
  28.   while (obj = obj.offsetParent) {
  29.   nleft += obj.offsetLeft
  30.   ntop += obj.offsetTop
  31.   }
  32.   }
  33.   return [nleft,ntop];
  34. }
  35.  
  36.  
  37. <a href="fdsf" onmouseover="menu(this, 1)">Menu 1</a> | <a href="fdsf" onmouseover="menu(this, 2)">Menu 2</a>


--------------------
FluxBB - lekki i szybki skrypt forum | Polskie wsparcie FluxBB
Go to the top of the page
+Quote Post
 
Start new topic
Odpowiedzi (1 - 7)
nevt
post
Post #2





Grupa: Przyjaciele php.pl
Postów: 1 595
Pomógł: 282
Dołączył: 24.09.2007
Skąd: Reda, Pomorskie.

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


dadaj obsługę tego zdarzenia do elementu menu:
Kod
menu.onmouseout = function(e){
      document.body.removeChild(menu);
document.body.appendChild(menu);


Ten post edytował nevt 14.02.2008, 07:50:08


--------------------

-
Oh no, my young coder. You will find that it is you who are mistaken, about a great many things... -
Go to the top of the page
+Quote Post
daris
post
Post #3





Grupa: Zarejestrowani
Postów: 78
Pomógł: 4
Dołączył: 7.01.2008

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


Mam coś zamienić na to czy tylko dodać to powyższe? Pozatym nie wiem czy mam ten cały kod wrzucić bo gdzieś wcięło klamrę } tongue.gif

Próbowałem zamieniać, dodawać i ogólnie eksperymentować ale żadnym sposobem nie udało mi się tego zrobić.

edit: a i
Kod
menu.style = 'jakis styl';

to działa tylko pod operą, więc musiałem to zamienić na:
Kod
menu.setAttribute('style', 'background: lime; border: 1px solid green; position:absolute; top:' + ypos + 'px; left: ' + xpos + 'px');


Ten post edytował daris 14.02.2008, 14:19:51


--------------------
FluxBB - lekki i szybki skrypt forum | Polskie wsparcie FluxBB
Go to the top of the page
+Quote Post
nevt
post
Post #4





Grupa: Przyjaciele php.pl
Postów: 1 595
Pomógł: 282
Dołączył: 24.09.2007
Skąd: Reda, Pomorskie.

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


po prostu (sorki za brak klamry w poprzednim poscie - pomylko przy kopiowaniu):
Kod
// tamgdzie masz teraz tylko:
document.body.appendChild(menu);

// zamien to na:
menu.onmouseout = function(e){ document.body.removeChild(menu); };
document.body.appendChild(menu);

powodzenia


--------------------

-
Oh no, my young coder. You will find that it is you who are mistaken, about a great many things... -
Go to the top of the page
+Quote Post
daris
post
Post #5





Grupa: Zarejestrowani
Postów: 78
Pomógł: 4
Dołączył: 7.01.2008

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


Takie coś nie działa. Już tak wcześniej próbowałem.

A czy ktoś już może napisał taki prosty skrypt dla menu? (bez żadnych animacji)


--------------------
FluxBB - lekki i szybki skrypt forum | Polskie wsparcie FluxBB
Go to the top of the page
+Quote Post
MajareQ
post
Post #6





Grupa: Zarejestrowani
Postów: 382
Pomógł: 22
Dołączył: 21.05.2007
Skąd: Elbląg

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


Kod
<a href="javascript: show_reds('1')">Menu</a>
<div class="show_redss" id="1">tresc menu</div>


questionmark.gif
Go to the top of the page
+Quote Post
daris
post
Post #7





Grupa: Zarejestrowani
Postów: 78
Pomógł: 4
Dołączył: 7.01.2008

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


Co to ma być?


--------------------
FluxBB - lekki i szybki skrypt forum | Polskie wsparcie FluxBB
Go to the top of the page
+Quote Post
MajareQ
post
Post #8





Grupa: Zarejestrowani
Postów: 382
Pomógł: 22
Dołączył: 21.05.2007
Skąd: Elbląg

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


To jest podpowiedź... winksmiley.jpg

Ten post edytował MajareQ 15.02.2008, 08:30:01
Go to the top of the page
+Quote Post

Reply to this topicStart new topic
1 Użytkowników czyta ten temat (1 Gości i 0 Anonimowych użytkowników)
0 Zarejestrowanych:

 



RSS Aktualny czas: 20.08.2025 - 20:38