ugrás a tartalomhoz

Menü kiakad

gtoma · 2011. Ápr. 15. (P), 08.36
Sziasztok!

Van egy js menü megjelenítőm. Nagyon jól működik, de sajnos időnként "fennakad".

Mit értek ez alatt?
Az ember megnyitja a menüt, majd gyorsan alt tabol, vagy másik fülre megy át, akkor NÉHA kinyílva marad a menü, és csak akkor csukódik be, ha fölé visszük az egeret.

Gondolom, hogy ez valamifajta böngésző probléma, de tud valaki olyan eseményt ami akkor aktiválódik, mikor "elveszti a fókuszt" az adott ablak? :D

Előre is köszönöm az 5letet!

íme a kód:
  1. var mcMenu=function(){  
  2.     var relAttrib=30,x=100,t=30,z=50,s=6,a;  
  3.     function dd(n){this.n=n;this.h=[];this.c=[]}  
  4.         dd.prototype.init=function(p,c){  
  5.         a=c;var w=document.getElementById(p), s=w.getElementsByTagName('ul'), i=0, x=w.getElementsByTagName('li'), xl=x.length;  
  6.                 for(i=0;i<xl;i++) {  
  7.                     var xxc = x[i].childNodes, xxl=xxc.length, ulvan = '';  
  8.                     for(xxi=0;xxi<xxl;xxi++) {if(xxc[xxi].tagName == 'UL' || xxc[xxi].tagName == 'ul') {ulvan = xxc[xxi];}}  
  9.                     var h=x[i];this.h[i]=h;  
  10.                     if( ulvan != '' ) {  
  11.                         this.c[i]=ulvan;  
  12.                         h.onmouseover=new Function(this.n+'.st('+i+',true)');  
  13.             h.onmouseout=new Function(this.n+'.st('+i+')');  
  14.                         //b = document.getElementsByTagName('body').item(0);  
  15.                         //b.onmouseout = new Function(this.n+'.st('+i+')');  
  16.                         //alert('-'+b);  
  17.             ulvan.setAttribute('rel''0');  
  18.                     } else {  
  19.                         //alert('LI');  
  20.                         this.c[i]=x[i];  
  21.                         h.onmouseover=new Function(this.n+'.sx('+i+',true)');  
  22.             h.onmouseout=new Function(this.n+'.sx('+i+')');  
  23.                     }  
  24.                 }  
  25.     }  
  26.     dd.prototype.st=function(x,f){  
  27.                 //var c=this.c[x], h=this.h[x], li=c.parentNode, li2=h.getElementsByTagName('a')[0];  
  28.                 var c=this.c[x], h=this.h[x], li=c.parentNode, li2 = li.childNodes[0];  
  29.         clearInterval(c.t);  
  30.         if(f){  
  31.                     if( !String(li.className).toLowerCase().match(a)) {li.className+=' '+a;}  
  32.                     if( !String(li2.className).toLowerCase().match(a)) {li2.className+=' '+a;}  
  33.                     if(!c.mh){c.style.display='block';c.style.height='';c.mh=c.offsetHeight;c.style.height=0;}  
  34.                     if(c.mh==c.offsetHeight){c.style.overflow='visible';c.setAttribute('rel', relAttrib);}  
  35.                     else{c.style.zIndex='100';c.t=setInterval(function(){sl(c,1)},t)}  
  36.         }else{c.style.zIndex='50';c.t=setInterval(function(){sl(c,-1)},t)}  
  37.         }  
  38.         dd.prototype.sx=function(x,f){  
  39.             //var c=this.c[x], h=this.h[x], li=c, li2=c.getElementsByTagName('a')[0];  
  40.             var c=this.c[x], h=this.h[x], li=c, li2 = c.childNodes[0];  
  41.             clearInterval(c.t);  
  42.             if(f){li.className+=' '+a;li2.className+=' '+a;}  
  43.                 else {li.className=li.className.replace(a,'');li2.className=li2.className.replace(a,'');}  
  44.         }  
  45.     function sl(c,f){  
  46.         var h=c.offsetHeight;  
  47.         if((h<=0&&f!=1)||(h>=c.mh&&f==1)){  
  48.                     if(f==1){  
  49.                             c.style.filter='';c.style.opacity=1;c.style.overflow='visible';  
  50.                             c.setAttribute('rel', relAttrib);  
  51.                     } else {  
  52.                         //x = c.parentNode; xa = x.getElementsByTagName('a')[0];  
  53.                         x = c.parentNode;xa = x.childNodes[0];  
  54.                         x.className=x.className.replace(a,'');xa.className=xa.className.replace(a,'');  
  55.                     }  
  56.                     clearInterval(c.t);return  
  57.         }  
  58.         var relAttribute = c.getAttribute('rel');  
  59.         relAttribute = parseInt(relAttribute);  
  60.         if( (relAttribute == 0) && (f==1) ) {  
  61.                     parentZar(c);  
  62.                     c.style.paddingTop = '';c.style.paddingBottom = '';  
  63.                 }  
  64.         if(relAttribute <= 0 || f==1) {  
  65.                         if(f!=1) {c.style.paddingTop = '0px';c.style.paddingBottom = '0px';c.style.zIndex='0';}  
  66.             c.style.overflow='hidden';  
  67.             var d = (f==1) ? Math.ceil( (c.mh-h)/s ) : Math.ceil(h/s), o=h/c.mh;  
  68.             c.style.height=h+(d*f)+'px';  
  69.             c.style.opacity=o;  
  70.                         c.style.filter='alpha(opacity='+(o*100)+')';  
  71.         } else if(f!=1) {  
  72.             relAttribute--;  
  73.             c.setAttribute('rel', relAttribute);  
  74.         }  
  75.     }  
  76.     function parentZar(c) {  
  77.         parentem = c.parentNode.parentNode;  
  78.         ss=parentem.getElementsByTagName('ul');ll=ss.length;i=0;  
  79.         for(i;i<ll;i++){  
  80.                     hh=ss[i];  
  81.                     relAttribute = hh.getAttribute('rel');  
  82.                     hh.setAttribute('rel''0');  
  83.                     hh.style.height='0px';  
  84.                     hh.style.opacity='0';  
  85.                     hh.style.filter='alpha(opacity=0)';  
  86.         }  
  87.     }  
  88.     return{dd:dd}  
  89. }();  
 
1

timer

ironwill · 2011. Ápr. 15. (P), 10.08
Egy időzítőt szoktak erre a célra beállítani, hogy egy idő tüntesse el a még látszódó almenüket.

Most nem tudok kódot mutatni, de hirtelen ezt találtam: http://javascript-array.com/scripts/simple_drop_down_menu/
2

Az van.

gtoma · 2011. Ápr. 18. (H), 14.35
Timer van benne. Pont az a lényeg, hogy az LEÁLL! :)

c.t=setInterval(function(){sl(c,1)},t)
3

clearInterval

Poetro · 2011. Ápr. 18. (H), 15.16
A clearInterval-lal pedig törlésre kerül.
4

az más

ironwill · 2011. Ápr. 18. (H), 17.50
Idő hiányában nem néztem át a kódot. Az én saram.

OFF: De, ha tudod, hogy mi a gond, akkor miért nem úgy teszed fel a kérdést?