var jsmanu = function () { //$("#menu").draggable(); var flag = true; var lic = document.queryselectorall(".navbox li h2"); //var lic = document.queryselectorall(".navbox li i"); // 主导航nav点击事件 for (var i = 0; i < lic.length; i++) { //init // lic[i].onclick = function () { if (flag) { // 节流阀 flag = false; settimeout(function () { flag = true; }, 500) // 自点 if (this.classname === "obfocus") { if (this.queryselector("i") != null && this.queryselector("i").classlist.length != 0) { this.queryselector("i").classlist.remove("arrowrot"); getnext(this).style.height = "0"; this.classlist.add("obtain"); this.classlist.remove("obfocus"); } return } var sec = getnext(this); var sib = []; if (sec != null && typeof sec.parentnode != "undefined") sib = siblings(sec.parentnode); var otherarr = []; var arrowclass = []; // 排他 secondary arrowrot obfocus for (var j = 0; j < sib.length; j++) { var sibsec = sib[j].getelementsbytagname('*'); for (var i = 0; i < sibsec.length; i++) { if (sibsec[i].classname == "secondary") {otherarr.push(sibsec[i]) } if (sibsec[i].classname == "arrowrot") {arrowclass.push(sibsec[i]) } if (sibsec[i].classname == "obfocus") {sibsec[i].classlist.remove("obfocus");sibsec[i].classlist.add("obtain"); } } } for (var i = 0; i < otherarr.length; i++) { otherarr[i].style.height = "0"; } if (arrowclass[0]) { arrowclass[0].classlist.remove("arrowrot"); } // 留自己 //sec.style.height = 2.5078 + "rem"; if (sec != null) sec.style.height = 'inherit'; if (this.getelementsbytagname("i") != null && this.getelementsbytagname("i").length != 0) this.getelementsbytagname("i")[0].classlist.add("arrowrot"); this.classlist.remove("obtain"); this.classlist.add("obfocus"); } } } // 子导航点击事件 var seconc = document.queryselectorall(".secondary h3") for (var i = 0; i < seconc.length; i++) { seconc[i].onclick = function () { for (var i = 0; i < seconc.length; i++) { seconc[i].classlist.remove("seconfocus"); } this.classlist.add("seconfocus"); } } // 隐藏菜单 var obscure = document.queryselector(".navh span"); var open = document.queryselector("#open"); var ensconce = document.queryselector("#ensconce"); obscure.onclick = function () { open.style.marginleft = "-300px"; settimeout(function () { ensconce.style.display = "block"; }, 350) } //显示菜单 var showc = document.queryselector("#ensconce h2"); showc.onclick = function () { open.style.marginleft = "0px"; settimeout(function () { ensconce.style.display = "none"; }, 100) } function getbyclass(clsname, parent) { var oparent = parent ? document.getelementbyid(parent) : document, boxarr = new array(), oelements = oparent.getelementsbytagname('*'); for (var i = 0; i < oelements.length; i++) { if (oelements[i].classname == clsname) { boxarr.push(oelements[i]); } } return boxarr; } // 获取下一个兄弟元素 function getnext(node) { if (!node.nextsibling) return null; var nextnode = node.nextsibling; if (nextnode.nodetype == 1) { return nextnode; } return getnext(node.nextsibling); } // 获取除了自己以外的其他亲兄弟元素 function siblings(elem) { var r = []; var n = elem.parentnode.firstchild; for (; n; n = n.nextsibling) { if (n.nodetype === 1 && n !== elem) { r.push(n); } } return r; } } /*settimeout(function () { jsmanu(); },1000)*/