gmiotto Posted December 7, 2011 Report Share Posted December 7, 2011 Opa! Sou nova na área de javascript, e estou tentando desenvolver um site para faculdade...Eu gostaria de saber como fazer para deixar o menu compactado, contraído, e que ele só abrisse se o usuário clicasse?Além disso, no IE o menu apresenta um pequeno erro. Quando clica para contrair, ele dá erro na imagem.Link do menu:C:\Documents and Settings\Cliente\Meus documentos\demar\menu.htmlCódigo java script:var remember = false; //Remember menu states, and restore them on next visit.var contractall_default= true; //Should all submenus be contracted by default? (true or false)var menu, titles, submenus, arrows, bypixels;var heights = new Array();var n = navigator.userAgent;if(/Opera/.test(n)) bypixels = 2;else if(/Firefox/.test(n)) bypixels = 3;else if(/MSIE/.test(n)) bypixels = 2;/////DD added expandall() and contractall() functions/////function slash_expandall(){if (typeof menu!="undefined"){ for(i=0; i<Math.max(titles.length, submenus.length); i++){ titles.className="title"; arrows.src = "menus1/fecha-preto.gif"; submenus.style.display=""; submenus.style.height = heights+"px"; }}}function slash_contractall(){if (typeof menu!="undefined"){ for(i=0; i<Math.max(titles.length, submenus.length); i++){ titles.className="titlehidden"; arrows.src = "menus1/fecha-preto.gif"; submenus.style.display="none"; submenus.style.height = 0; }}}/////End DD added functions///////////////////////////////function init(){ menu = getElementsByClassName("sdmenu", "div", document)[0]; titles = getElementsByClassName("title", "span", menu); submenus = getElementsByClassName("submenu", "div", menu); arrows = getElementsByClassName("arrow", "img", menu); for(i=0; i<Math.max(titles.length, submenus.length); i++) { titles.onclick = gomenu; arrows.onclick = gomenu; heights = submenus.offsetHeight; submenus.style.height = submenus.offsetHeight+"px"; } if(remember) restore() else if (contractall_default) //DD added code slash_contractall() //DD added code}function restore() { if(getcookie("menu") != null) { var hidden = getcookie("menu").split(","); for(var i in hidden) { titles[hidden].className = "titlehidden"; submenus[hidden].style.height = "0px"; submenus[hidden].style.display = "none"; arrows[hidden].src = "menus1/fecha-preto.gif"; } }}function gomenu(e) { if (!e) var e = window.event; var ce = (e.target) ? e.target : e.srcElement; var sm; for(var i in titles) { if(titles == ce || arrows == ce) sm = i; } if(parseInt(submenus[sm].style.height) > parseInt(heights[sm])-2) { hidemenu(sm); } else if(parseInt(submenus[sm].style.height) < 2) { titles[sm].className = "title"; showmenu(sm); }}function hidemenu(sm) { var nr = submenus[sm].getElementsByTagName("a").length*bypixels; submenus[sm].style.height = (parseInt(submenus[sm].style.height)-nr)+"px"; var to = setTimeout("hidemenu("+sm+")", 30); if(parseInt(submenus[sm].style.height) <= nr) { clearTimeout(to); submenus[sm].style.display = "none"; submenus[sm].style.height = "0px"; arrows[sm].src = "menus1/fecha-preto.gif"; titles[sm].className = "titlehidden"; }}function showmenu(sm) { var nr = submenus[sm].getElementsByTagName("a").length*bypixels; submenus[sm].style.display = ""; submenus[sm].style.height = (parseInt(submenus[sm].style.height)+nr)+"px"; var to = setTimeout("showmenu("+sm+")", 30); if(parseInt(submenus[sm].style.height) > (parseInt(heights[sm])-nr)) { clearTimeout(to); submenus[sm].style.height = heights[sm]+"px"; arrows[sm].src = "menus1/fecha-preto.gif"; } }function store() { var hidden = new Array(); for(var i in titles) { if(titles.className == "titlehidden") hidden.push(i); } putcookie("menu", hidden.join(","), 30);}function getElementsByClassName(strClassName, strTagName, oElm){ var arrElements = (strTagName == "*" && document.all)? document.all : oElm.getElementsByTagName(strTagName); var arrReturnElements = new Array(); strClassName = strClassName.replace(/\-/g, "\\-"); var oRegExp = new RegExp("(^|\\s)" + strClassName + "(\\s|$)"); var oElement; for(var i=0; i<arrElements.length; i++){ oElement = arrElements; if(oRegExp.test(oElement.className)){ arrReturnElements.push(oElement); } } return (arrReturnElements)}function putcookie(c_name,value,expiredays) { var exdate=new Date(); exdate.setDate(exdate.getDate()+expiredays); document.cookie = c_name + "=" + escape(value) + ((expiredays==null) ? "" : ";expires="+exdate);}function getcookie(c_name) { if(document.cookie.length > 0) { var c_start = adocument.cookie.indexOf(c_name + "="); if(c_start != -1) { c_start = c_start + c_name.length + 1; var c_end = document.cookie.indexOf(";",c_start); if(c_end == -1) c_end = document.cookie.length; return unescape(document.cookie.substring(c_start, c_end)); } } return null;}window.onload = init;if(remember) window.onunload = store;Se alguém puder ajudar, agradeço muito!!!!!! Quote Link to comment Share on other sites More sharing options...
0 fiote Posted December 7, 2011 Report Share Posted December 7, 2011 Amigo, a gente não tem acesso ao seu C: :P Quote Link to comment Share on other sites More sharing options...
Question
gmiotto
Opa! Sou nova na área de javascript, e estou tentando desenvolver um site para faculdade...
Eu gostaria de saber como fazer para deixar o menu compactado, contraído, e que ele só abrisse se o usuário clicasse?
Além disso, no IE o menu apresenta um pequeno erro. Quando clica para contrair, ele dá erro na imagem.
Link do menu:
C:\Documents and Settings\Cliente\Meus documentos\demar\menu.html
Código java script:
Se alguém puder ajudar, agradeço muito!!!!!!
Link to comment
Share on other sites
1 answer to this question
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.