javascript_javascript 스킬로 트리 메뉴 구현하는 방법

WBOY
풀어 주다: 2016-05-16 15:49:54
원래의
1249명이 탐색했습니다.

이 기사의 예에서는 JavaScript로 트리 메뉴를 구현하는 방법을 설명합니다. 참고할 수 있도록 모든 사람과 공유하세요. 세부 내용은 다음과 같습니다.

var ME={
  ini:{i:true,d:{},d1:{},h:0,h1:0,h2:0},
  html:function(da,f){
    var s='<ul'+(f&#63;' class="f"':'')+'>';
    for(var i=0,l=da.length;i<l;i++){
      if(typeof(da[i].pid)=='object'){
        s+='<li><button type="button" class="'+(i==0&&this.ini.i&#63;'s1':(i+1==l&#63;'s5':'s3'))+'" onclick="ME.yc(this)"></button><span><button type="button" class="r1"></button><a href="javascript:;">'+da[i].ming+'</a></span>';
        this.ini.i=false;
        s+=this.html(da[i].pid,(i+1==l));
      }else{
        s+='<li><button type="button" class="'+(i+1==l&#63;'e3':'e1')+'"></button><span><button type="button" class="m1"></button><a href="http://www.jb51.net" target="mainFrame">'+da[i].ming+'</a></span>';
      }
      s+='</li>';
    }
    s+='</ul>';
    return s;
  },
  st:function(id,da){
    document.getElementById(id).innerHTML=this.html(da);
  },
  yc:function(a){
    var s=a.className.substr(1);
    if(s%2){
      this.ini.d=a.parentNode.children[2];
      this.ini.h1=this.hei(this.ini.d);
      this.ini.h3=this.ini.h1/10;
      this.yc1(1);
      a.className='s'+(parseInt(s)+1);
      a.parentNode.children[1].children[0].className='r2';
      var ol=a.parentNode.parentNode._;
      if(typeof(ol)=='object'){
        this.ini.d1=ol;
        this.ini.h=ol.offsetHeight;
        this.ini.h2=this.ini.h/10;
        this.yc2(1);
        ol.parentNode.children[0].className='s'+(parseInt(ol.parentNode.children[0].className.substr(1))-1);
        ol.parentNode.children[1].children[0].className='r1';
      }
      a.parentNode.parentNode._=a.parentNode.children[2];
    }else{
      this.ini.d1=a.parentNode.children[2];
      this.ini.h=this.ini.d1.offsetHeight;
      this.ini.h2=this.ini.h/10;
      this.yc2(1);
      a.className='s'+(parseInt(s)-1);
      a.parentNode.children[1].children[0].className='r1';
      a.parentNode.parentNode._='';
    }
  },
  yc1:function(b){
    var h1=ME.ini.h1-(11/(b+1)-1)*ME.ini.h3;
    with(ME.ini.d.style){
      height=h1+'px';
      display='block';
    }
    if(b<10){
    setTimeout('ME.yc1('+(b+1)+')',25);
    }else{
    ME.ini.d.style.display='block';
    ME.ini.d.style.height='';
    }
  },
  yc2:function(b){
    var h1=(11/(b+1)-1)*ME.ini.h2;
    with(ME.ini.d1.style){
      height=h1+'px';
    }
    if(b<10){
    setTimeout('ME.yc2('+(b+1)+')',25);
    }else{
    ME.ini.d1.style.display='';
    ME.ini.d1.style.height='';
    }
  },
  hei:function(a){
    var b=a.cloneNode(true);
    b.style.position='absolute'; 
    b.style.display='block'; 
    b.style.visibility='hidden';
    a.parentNode.appendChild(b);
    var h=b.offsetHeight;
    a.parentNode.removeChild(b);
    return h;
  }
}

로그인 후 복사

이 기사가 모든 사람의 JavaScript 프로그래밍 설계에 도움이 되기를 바랍니다.

관련 라벨:
원천:php.cn
본 웹사이트의 성명
본 글의 내용은 네티즌들의 자발적인 기여로 작성되었으며, 저작권은 원저작자에게 있습니다. 본 사이트는 이에 상응하는 법적 책임을 지지 않습니다. 표절이나 침해가 의심되는 콘텐츠를 발견한 경우 admin@php.cn으로 문의하세요.
인기 튜토리얼
더>
최신 다운로드
더>
웹 효과
웹사이트 소스 코드
웹사이트 자료
프론트엔드 템플릿
회사 소개 부인 성명 Sitemap
PHP 중국어 웹사이트:공공복지 온라인 PHP 교육,PHP 학습자의 빠른 성장을 도와주세요!