JS实现类似百叶窗下拉菜单效果
废话不多说了,直接给大家贴代码了,具体代码如下所示:
functionleftmove(){ varoLeft_ul=document.getElementById('left_ul'); varaLeft_li=oLeft_ul.children;//获得左侧ul下的第一个子集li varaleft_ul_hidden=oLeft_ul.getElementsByTagName('ul'); varaleft_span_hidden=oLeft_ul.getElementsByTagName('span'); vararr=[]; varspan_arr=[]; getclassname(aleft_ul_hidden,'cl_hidden',arr) getclassname(aleft_span_hidden,'sj',span_arr); for(vari=0;i<aLeft_li.length;i++){ aLeft_li[i].index=i; aLeft_li[i].onmouseenter=function(){ for(varj=0;j<aLeft_li.length;j++){ move(aLeft_li[j],{height:40}); span_arr[j].style.borderColor='#f2f2f2#f2f2f2#f2f2f2#666'; span_arr[j].style.top='13px'; span_arr[j].style.left='8px'; } varul_height=arr[this.index].children.length*40 move(aLeft_li[this.index],{height:40+ul_height}); span_arr[this.index].style.borderColor='#666#0ad#0ad#0ad'; span_arr[this.index].style.top='17px'; span_arr[this.index].style.left='6px'; }; aLeft_li[i].onmouseleave=function(){ for(varj=0;j<aLeft_li.length;j++){ move(aLeft_li[j],{height:40}); span_arr[j].style.borderColor='#f2f2f2#f2f2f2#f2f2f2#666'; span_arr[j].style.top='13px'; span_arr[j].style.left='8px'; } }; arr[i].onmouseover=function(){ for(vari=0;i<arr.length;i++){ span_arr[i].style.borderColor='#f2f2f2#f2f2f2#f2f2f2#666'; span_arr[i].style.top='13px'; span_arr[i].style.left='8px'; } span_arr[this.parentNode.index].style.borderColor='#666#f2f2f2#f2f2f2#f2f2f2'; span_arr[this.parentNode.index].style.top='17px'; span_arr[this.parentNode.index].style.left='6px'; }; arr[i].onmouseout=function(){ for(vari=0;i<arr.length;i++){ span_arr[i].style.borderColor='#f2f2f2#f2f2f2#f2f2f2#666'; span_arr[i].style.top='13px'; span_arr[i].style.left='8px'; } span_arr[this.parentNode.index].style.borderColor='#666#0ad#0ad#0ad'; span_arr[this.parentNode.index].style.top='17px'; span_arr[this.parentNode.index].style.left='6px'; }; } } leftmove();