Fehler in einem Skript! (
Christopher Schmidt
- javascript
Hallo,
ich habe einen Fehler in einem Skript. Der Fehler leigt (meine ich), in diesen Zeilen:
//Changes background onmouseoverfunction menuOver(num){oTopMenu[num][1].bgChange(nBgcolorchangeto)}function menuOut(num){oTopMenu[num][1].bgChange(nBgcolor)}
Aber nun zum Problem:
Die Function F verhält sich nicht mit der Function des Nav-Menüs. (das Menü oben, was nach dem BODY deffiniert wird!). Ich habe schon viel probiert, Variablen und Function umbenannt, aber es funktioniert aber nichts!
Das Problem ist augenscheinlich nicht zu sehen. Wenn man aber Über das Menü (rechts oben) mit der Mausrfährt, passiert nicht. Wenn ich nun die Function F im Onload auskommentiere, wird beim MOUSEOVER die Unterseite des Menüs gehovert!
Hier eine verkürzte Version des Codes:
<html><head><style>
.clTopMenu {position:absolute; width:56px; height:150px; clip:rect(0px, 56px, 14px, 0px); background-color:#eeeeee; z-index:31; visibility:hidden;} .clTopMenuBottom {position:absolute; width:56px; height:3px; clip:rect(0px, 56px, 3px, 0px); top:11; background-color:#cecfce; z-index:2;} .clTopMenuText {position:absolute; width:91px; left:5px; top:15px; font-family:arial,helvetica,sans-serif; font-size:11px; background-color:#eeeeee; z-index:1;}
</style><script> //////////////////////
// in Array Lc und Fc werden die jeweiligen Anfangs- und Endfarben als rgb-Werte eingetragen // existiert kein Arrayeintrag für einen Link, wird der letzte genommen, der allerdings nicht 'n' sein darf. // var s ist die Schnelligkeit des Fades, die browser unterscheiden sich hier erheblich.
var Lc = [[71,170,255]];
var Fc = [[0,0,134]];
var s = 1;
var d = document, dl = d.getElementsByTagName('a'); function F() {var C = function(c){return 'rgb(' + c[0] + ',' + c[1] + ',' + c[2] +')'}, cI = function(i){clearInterval(i)}, aC = function(ac){var l = ac.length-1; return ac[i] ? ac[i] : [ac[l][0], ac[l][1], ac[l][2]]}, m = function(t, n){cI(t.sid); t.f(n)};
for(var i = 0, di; i < dl.length; i++) if((di = dl[i]).className != 'n') {di.c = []; with(di){c[0] = aC(Lc); style.color = C(c[1] = [c[0][0], c[0][1], c[0][2]]); c[2] = aC(Fc)}; di.f = function(z) {var t = this, a = t.c[1], o = t.c[z != 1 ? 0 : 2];
t.v = function(x){with(t) a[x] > o[x] ? a[x]-- : a[x] < o[x] ? a[x]++ : a[x] = o[x]}; t.p = function(x){with(t) return c[0][x] > c[2][x] ? a[x]*z < (o[x] + z)*z : a[x]*z > (o[x] - z)*z};
t.sid = setInterval( function(){ with(t){for(j in a) v(j); p(0) && p(1) && p(2) ? cI(sid) : 0; style.color = C(a)}}, s); }; di.onmouseover = function(){m(this, 1)}; di.onmouseout = function(){m(this,-1)}; }; };
/////////////////////////////////////////////////////////////////////////// ///////////////////////////////////////////////////////////////////////////
var d = document, Cla = [], Cda =[]; function H(o, h1, h2)
{for (var i = 0; i < (td = d.getElementsByTagName('td')).length, t = td[i]; i++)
o == 1 ? (T(t, h1 ? T(t, T(t) == h1 ? h2 : Cla[i]) : Cla[i]), D(t, T(t) == h2 ? 'nix' : Cda[i])) : (Cla[i] = T(t), Cda[i] = D(t));
};
function D(d, n){return n ? d.id = n : d.id}; function T(t, n){return n ? t.className = n: t.className};
/********************************************************************************** NewsMenu * Copyright (C) 2001 <a href="/dhtmlcentral/thomas_brattli.asp">Thomas Brattli</a> * This script was released at DHTMLCentral.com * Visit for more great scripts! * This may be used and changed freely as long as this msg is intact! * We will also appreciate any links you could give us. * * Made by <a href="/dhtmlcentral/thomas_brattli.asp">Thomas Brattli</a> *********************************************************************************/
function lib_bwcheck(){ //Browsercheck (needed) this.ver=navigator.appVersion this.agent=navigator.userAgent this.dom=document.getElementById?1:0 this.opera5=this.agent.indexOf("Opera 5")>-1 this.ie5=(this.ver.indexOf("MSIE 5")>-1 && this.dom && !this.opera5)?1:0; this.ie6=(this.ver.indexOf("MSIE 6")>-1 && this.dom && !this.opera5)?1:0; this.ie4=(document.all && !this.dom && !this.opera5)?1:0; this.ie=this.ie4||this.ie5||this.ie6 this.mac=this.agent.indexOf("Mac")>-1 this.ns6=(this.dom && parseInt(this.ver) >= 5) ?1:0; this.ns4=(document.layers && !this.dom)?1:0; this.bw=(this.ie6 || this.ie5 || this.ie4 || this.ns4 || this.ns6 || this.opera5) return this } var bw=new lib_bwcheck()
/******************************************************************************** If you want to change the appearance of the text, background-colors, size or anything do that in the style tag above.
This menu might not be as easy to adapt to your own site, but please play around with it before you mail me for help... ****************************************************************************/
/*************************************************************************** Variables to set. ****************************************************************************/
//There are 2 ways these menus can be placed // 0 = column // 1 = row nPlace=0
//How many menus do you have? (remember to copy and add divs in the body if you add menus) var nNumberOfMenus=2
var nMwidth=56 //The width on the menus (set the width in the stylesheet as well) var nPxbetween=2 //Pixels between the menus var nFromright=0 //The first menus left position var nFromtop=0 //The top position of the menus var nBgcolor='#CECFCE' //The bgColor of the bottom mouseover div var nBgcolorchangeto='#6380BC' //The bgColor to change to var nImageheight=11 //The position the mouseover line div will stop at when going up!
/*************************************************************************** You shouldn't have to change anything below this ****************************************************************************/ //Object constructor function makeNewsMenu(obj,nest){ nest=(!nest) ? "":'document.'+nest+'.' this.css=bw.dom? document.getElementById(obj).style:bw.ie4?document.all[obj].style:bw.ns4?eval(nest+"document.layers." +obj):0; this.evnt=bw.dom? document.getElementById(obj):bw.ie4?document.all[obj]:bw.ns4?eval(nest+"document.layers." +obj):0; this.scrollHeight=bw.ns4?this.css.document.height:this.evnt.offsetHeight this.moveIt=b_moveIt;this.bgChange=b_bgChange; this.slideUp=b_slideUp; this.slideDown=b_slideDown; this.clipTo=b_clipTo; this.obj = obj + "Object"; eval(this.obj + "=this") } //Objects methods
// A unit of measure that will be added when setting the position of a layer. var px = bw.ns4||window.opera?"":"px";
function b_moveIt(x,y){this.x=x; this.y=y; this.css.right=this.x+px; this.css.top=this.y+px;} function b_bgChange(color){this.css.backgroundColor=color; this.css.bgColor=color; this.css.background=color;} function b_clipTo(t,r,b,l){ if(bw.ns4){this.css.clip.top=t; this.css.clip.right=r; this.css.clip.bottom=b; this.css.clip.right=l }else this.css.clip="rect("+t+"px "+r+"px "+b+"px "+l+"px)"; } function b_slideUp(ystop,moveby,speed,fn,wh){ if(!this.slideactive){ if(this.y>ystop){ this.moveIt(this.x,this.y-5); eval(wh) setTimeout(this.obj+".slideUp("+ystop+","+moveby+","+speed+",'"+fn+"','"+wh+"')",speed) }else{ this.slideactive=false; this.moveIt(0,ystop); eval(fn) } } } function b_slideDown(ystop,moveby,speed,fn,wh){ if(!this.slideactive){ if(this.y<ystop){ this.moveIt(this.x,this.y+5); eval(wh) setTimeout(this.obj+".slideDown("+ystop+","+moveby+","+speed+",'"+fn+"','"+wh+"')",speed) }else{ this.slideactive=false; this.moveIt(0,ystop); eval(fn) } } } //Initiating the page, making cross-browser objects function newsMenuInit(){ oTopMenu=new Array() zindex=10 for(i=0;i<=nNumberOfMenus;i++){ oTopMenu[i]=new Array() oTopMenu[i][0]=new makeNewsMenu('divTopMenu'+i) oTopMenu[i][1]=new makeNewsMenu('divTopMenuBottom'+i,'divTopMenu'+i) oTopMenu[i][2]=new makeNewsMenu('divTopMenuText'+i,'divTopMenu'+i) oTopMenu[i][1].moveIt(0,nImageheight) oTopMenu[i][0].clipTo(0,nMwidth,nImageheight+3,0) if(!nPlace) oTopMenu[i][0].moveIt(inMwidth+nFromright+(inPxbetween),nFromtop) else{ oTopMenu[i][0].moveIt(nFromright,inImageheight+nFromtop+(inPxbetween)) oTopMenu[i][0].css.zIndex=zindex-- } oTopMenu[i][0].css.visibility="visible" } } //Moves the menu function topMenu(num){ if(oTopMenu[num][1].y==nImageheight) oTopMenu[num][1].slideDown(oTopMenu[num][2].scrollHeight+20,10,40,'oTopMenu['+num+'][0].clipTo(0,nMwidth,oTopMenu['+num+'][1].y+3,0)','oTopMenu['+num+'][0].clipTo(0,nMwidth,oTopMenu['+num+'][1].y+3,0)') else if(oTopMenu[num][1].y==oTopMenu[num][2].scrollHeight+20) oTopMenu[num][1].slideUp(nImageheight,10,40,'oTopMenu['+num+'][0].clipTo(0,nMwidth,oTopMenu['+num+'][1].y+3,0)','oTopMenu['+num+'][0].clipTo(0,nMwidth,oTopMenu['+num+'][1].y+3,0)') } //Changes background onmouseover function menuOver(num){oTopMenu[num][1].bgChange(nBgcolorchangeto)} function menuOut(num){oTopMenu[num][1].bgChange(nBgcolor)}
//Calls the init function onload if the browser is ok... // if (bw.bw) onload = newsMenuInit;
/////////////////////////////////////////////////////////////////////////// ///////////////////////////////////////////////////////////////////////////
function ONLOAD() { F(); if(bw.bw)newsMenuInit(); }; onload = ONLOAD; </script> </head><body>
<a href="xyz">Testlink</a> <div id=divTopMenu2 class=clTopMenu> <a href=../chat/ onmouseover=menuOver(2) onmouseout=menuOut(2) onclick="window.location.href='../chat/'" onfocus=if(this.blur)this.blur();> <img src=../daten/navchat.gif height=11 alt="" border=0 align=top></a> <div id=divTopMenuText2 class=clTopMenuText></div> <div id=divTopMenuBottom2 class=clTopMenuBottom></div></div> <div id=divTopMenu1 class=clTopMenu> <a href=# onmouseover=menuOver(1) onmouseout=menuOut(1) onclick="topMenu(1); return false;" onfocus=if(this.blur)this.blur();><img src=../daten/navkontakt.gif height=11 alt="" border=0 align=top></a> <div id=divTopMenuText1 class=clTopMenuText><a href=../andere/mail.php class="n" style="color: #000000; font-size: 10px;">EMail</a> <br><br> <a href=../gaestebuch/ class="n" style="color: #000000; font-size: 10px;">Gästebuch</a></div> <div id=divTopMenuBottom1 class=clTopMenuBottom></div></div><div id=divTopMenu0 class=clTopMenu><a href=# onmouseover=menuOver(0) onmouseout=menuOut(0) onclick="topMenu(0); return false;" onfocus=if(this.blur)this.blur();> <img src=../daten/navandere.gif height=11 alt="" border=0 align=top></a> <div id=divTopMenuText0 class=clTopMenuText><a href=../andere/sitemap.php class="n" style="color: #000000; font-size: 10px;">SiteMap</a><br><br><a href=../andere/impressum.php class="n" style="color: #000000; font-size: 10px;">Impressum</a></div><div id=divTopMenuBottom0 class=clTopMenuBottom></div>
</body></html>
Ich finde, das Problem ist (für Profis) am einfachsten zu lösen, indem man mal den Quelltext in eine *.html-Datei kopiert. Wenn MAN dann über ein Bild des Menüs fährst, sollte die unterseite des Menüs per JavaScript gehovert werden. (kein Bilderwechsel sonder ein Farbtausch des "Bottomdivs". So ein Div ist z.B. <div id=divTopMenuBottom2 class=clTopMenuBottom></div>). Dies funktioniert aber nicht. Wenn ich aber die Function F() aus dem ONLOAD auskommentiere, funktioniert der Hover.
Grüße aus BO,
Chrissi
Viele Grüße aus Bad Oeynhausen, Christopher Schmidt
PS: Ich möchte nicht sagen, mach mal, sucht mir die Fehler. Aber ich selbst probiere jetzt schon ganz lange, und irgendwie finde ich nicht das Problem.
Moin,
ich habe einen Fehler in einem Skript.
was genau willst du mit deinem Skript erreichen?
willst du das Teil unten dem nav-teil nur die Farbe verändern oder willst du da noch irgendwas setzen?
cu, javascriptmaster