Menü kiakad
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:
■ 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:
- var mcMenu=function(){
- var relAttrib=30,x=100,t=30,z=50,s=6,a;
- function dd(n){this.n=n;this.h=[];this.c=[]}
- dd.prototype.init=function(p,c){
- a=c;var w=document.getElementById(p), s=w.getElementsByTagName('ul'), i=0, x=w.getElementsByTagName('li'), xl=x.length;
- for(i=0;i<xl;i++) {
- var xxc = x[i].childNodes, xxl=xxc.length, ulvan = '';
- for(xxi=0;xxi<xxl;xxi++) {if(xxc[xxi].tagName == 'UL' || xxc[xxi].tagName == 'ul') {ulvan = xxc[xxi];}}
- var h=x[i];this.h[i]=h;
- if( ulvan != '' ) {
- this.c[i]=ulvan;
- h.onmouseover=new Function(this.n+'.st('+i+',true)');
- h.onmouseout=new Function(this.n+'.st('+i+')');
- //b = document.getElementsByTagName('body').item(0);
- //b.onmouseout = new Function(this.n+'.st('+i+')');
- //alert('-'+b);
- ulvan.setAttribute('rel', '0');
- } else {
- //alert('LI');
- this.c[i]=x[i];
- h.onmouseover=new Function(this.n+'.sx('+i+',true)');
- h.onmouseout=new Function(this.n+'.sx('+i+')');
- }
- }
- }
- dd.prototype.st=function(x,f){
- //var c=this.c[x], h=this.h[x], li=c.parentNode, li2=h.getElementsByTagName('a')[0];
- var c=this.c[x], h=this.h[x], li=c.parentNode, li2 = li.childNodes[0];
- clearInterval(c.t);
- if(f){
- if( !String(li.className).toLowerCase().match(a)) {li.className+=' '+a;}
- if( !String(li2.className).toLowerCase().match(a)) {li2.className+=' '+a;}
- if(!c.mh){c.style.display='block';c.style.height='';c.mh=c.offsetHeight;c.style.height=0;}
- if(c.mh==c.offsetHeight){c.style.overflow='visible';c.setAttribute('rel', relAttrib);}
- else{c.style.zIndex='100';c.t=setInterval(function(){sl(c,1)},t)}
- }else{c.style.zIndex='50';c.t=setInterval(function(){sl(c,-1)},t)}
- }
- dd.prototype.sx=function(x,f){
- //var c=this.c[x], h=this.h[x], li=c, li2=c.getElementsByTagName('a')[0];
- var c=this.c[x], h=this.h[x], li=c, li2 = c.childNodes[0];
- clearInterval(c.t);
- if(f){li.className+=' '+a;li2.className+=' '+a;}
- else {li.className=li.className.replace(a,'');li2.className=li2.className.replace(a,'');}
- }
- function sl(c,f){
- var h=c.offsetHeight;
- if((h<=0&&f!=1)||(h>=c.mh&&f==1)){
- if(f==1){
- c.style.filter='';c.style.opacity=1;c.style.overflow='visible';
- c.setAttribute('rel', relAttrib);
- } else {
- //x = c.parentNode; xa = x.getElementsByTagName('a')[0];
- x = c.parentNode;xa = x.childNodes[0];
- x.className=x.className.replace(a,'');xa.className=xa.className.replace(a,'');
- }
- clearInterval(c.t);return
- }
- var relAttribute = c.getAttribute('rel');
- relAttribute = parseInt(relAttribute);
- if( (relAttribute == 0) && (f==1) ) {
- parentZar(c);
- c.style.paddingTop = '';c.style.paddingBottom = '';
- }
- if(relAttribute <= 0 || f==1) {
- if(f!=1) {c.style.paddingTop = '0px';c.style.paddingBottom = '0px';c.style.zIndex='0';}
- c.style.overflow='hidden';
- var d = (f==1) ? Math.ceil( (c.mh-h)/s ) : Math.ceil(h/s), o=h/c.mh;
- c.style.height=h+(d*f)+'px';
- c.style.opacity=o;
- c.style.filter='alpha(opacity='+(o*100)+')';
- } else if(f!=1) {
- relAttribute--;
- c.setAttribute('rel', relAttribute);
- }
- }
- function parentZar(c) {
- parentem = c.parentNode.parentNode;
- ss=parentem.getElementsByTagName('ul');ll=ss.length;i=0;
- for(i;i<ll;i++){
- hh=ss[i];
- relAttribute = hh.getAttribute('rel');
- hh.setAttribute('rel', '0');
- hh.style.height='0px';
- hh.style.opacity='0';
- hh.style.filter='alpha(opacity=0)';
- }
- }
- return{dd:dd}
- }();
timer
Most nem tudok kódot mutatni, de hirtelen ezt találtam: http://javascript-array.com/scripts/simple_drop_down_menu/
Az van.
c.t=setInterval(function(){sl(c,1)},t)
clearInterval
az más
OFF: De, ha tudod, hogy mi a gond, akkor miért nem úgy teszed fel a kérdést?