jsパッケージの良いタブ効果コードです。



<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312">
<title>    www.jb51.net</title>
<script type="text/javascript">
/*
    
    by 
    2008-2-4
*/
opCard = function()
{
    this.bind = new Array();
    this.index = 0;        // , 0

    this.style = new Array();        //["","",""]
    this.overStyle = false;        // over, out , this.style[2]
    this.overChange = false;        // over, out
    this.menu = false;                //
    this.nesting = [false,false,"",""];        // , 2 menu,info id

    this.auto = [false, 1000];        // [true,2000]
    this.timerID = null;            //
    this.menutimerID = null;        //

    this.creat = function(func)
    {
        var _arrMenu = document.getElementById(this.bind[0]).getElementsByTagName(this.bind[1]);
        var _arrInfo = document.getElementById(this.bind[2]).getElementsByTagName(this.bind[3]);
        var my = this, i;
        var argLen = arguments.length;
        var arrM = new Array();

        if(this.nesting[0] || this.nesting[1])    // 
        {    // 
            var arrMenu = this.nesting[0]?getChilds(_arrMenu,this.bind[0],2):_arrMenu;
            var arrInfo = this.nesting[1]?getChilds(_arrInfo,this.bind[2],3):_arrInfo;
        }
        else
        {
            var arrMenu = _arrMenu;
            var arrInfo = _arrInfo;
        }

        var l = arrMenu.length;
        if(l!=arrInfo.length){alert("
, 。")}

        // 
        if(this.menu){this.auto=false;this.overChange=true;} // , , over, out

        // 
        for(i=0;i<l;i++)
        {
            arrMenu[i].cName = arrMenu[i].className;
            arrMenu[i].className = (i!=this.index || this.menu)?getClass(arrMenu[i],this.style[0]):getClass(arrMenu[i],this.style[1]);        // ,

            if(arrMenu[i].getAttribute("skip")) // 
            {
                if(this.overStyle || this.overChange)    //  over, out     
                {
                    arrMenu[i].onmouseover = function(){changeTitle(this, 2);autoStop(this, 0);}
                    arrMenu[i].onmouseout = function(){changeTitle(this, 0);autoStop(this, 1);}
                }
                arrMenu[i].onclick = function(){if(argLen==1){func()}}
                arrInfo[i].style.display = "none";
                continue;
            }

            if(i!=this.index || this.menu){arrInfo[i].style.display="none"};    // ,
            arrMenu[i].index = i;    // [ ]
            arrInfo[i].index = i;

            
            if(this.overChange)    // over, out
            {
                arrMenu[i].onmouseover = function(){changeOption(this);my.menu?changeMenu(1):autoStop(this, 0);}
                arrMenu[i].onmouseout = function(){changeOption(this);my.menu?changeMenu(0):autoStop(this, 1);}
            }
            else    //onclick
            {
                arrMenu[i].onclick = function(){changeOption(this);autoStop(this, 0);if(argLen==1){func()}}
                if(this.overStyle)    //  over, out 
                {
                    arrMenu[i].onmouseover = function(){changeTitle(this, 2);autoStop(this, 0);}
                    arrMenu[i].onmouseout = function(){changeTitle(this, 0);autoStop(this, 1);}
                }
                else    //  over, out 
                {
                    if(this.auto[0])    // 
                    {
                        arrMenu[i].onmouseover = function(){autoStop(this, 0);}
                        arrMenu[i].onmouseout = function(){autoStop(this, 1);}
                    }
                }
            }

            if(this.auto[0] || this.menu)    //arrinfo 
            {
                arrInfo[i].onmouseover = function(){my.menu?changeMenu(1):autoStop(this, 0);}
                arrInfo[i].onmouseout = function(){my.menu?changeMenu(0):autoStop(this, 1);}
            }
        }    //for

        if(this.auto[0])
        {
            this.timerID = setTimeout(autoMove,this.auto[1])
        }

        // 
        function autoMove()
        {
            var n;
            n = my.index + 1;
            if(n==l){n=0};
            while(arrMenu[n].getAttribute("skip"))        // 
            {
                n += 1;
                if(n==l){n=0};
            }
            changeOption(arrMenu[n]);
            my.timerID = setTimeout(autoMove,my.auto[1]);
        }

        // onmouseover , 。num:0 over,1 out。 obj 。 -_-!!
        function autoStop(obj, num)
        {
            if(!my.auto[0]){return;}
            //if(obj.index==my.index)
            num == 0 ? clearTimeout(my.timerID) : my.timerID = setTimeout(autoMove,my.auto[1]);
        }

        // 
        function changeOption(obj)
        {
            arrMenu[my.index].className = getClass(arrMenu[my.index],my.style[0]);    //
            arrInfo[my.index].style.display = "none";    //

            obj.className = getClass(obj,my.style[1]);        //
            arrInfo[obj.index].style.display = "";    //

            my.index = obj.index;    // index
        }

        /*        
             onclick ,overStyle onmouseover,onmouseout 。
            obj: 。    num:1 over,0 out
        */
        function changeTitle(obj, num)
        {
            if(!my.overStyle){return;};
            if(obj.index!=my.index){obj.className = getClass(obj,my.style[num])}
        }

        /*        
            
            obj: 。    num:1 over,0 out
        */
        function changeMenu(num)
        {
            if(!my.menu){return;}
            num==0?my.menutimerID = setTimeout(menuClose,1000):clearTimeout(my.menutimerID)
        }

        //
        function menuClose()
        {
            arrInfo[my.index].style.display = "none";
            arrMenu[my.index].className = my.style[0];
        }

        //  className( )
        function getClass(o, s)
        {
            if(o.cName==""){return s}
            else{return o.cName + " " + s}
        }

        //
        function getChilds(arrObj, id, num)
        {
            var depth = 0;
            var firstObj = my.nesting[num]==""?arrObj[0]:document.getElementById(my.nesting[num]);        //
            do    //
            {
                if(firstObj.parentNode.getAttribute("id")==id){break}else{depth+=1}
                firstObj = firstObj.parentNode;
            }
            while(firstObj.tagName.toLowerCase()!="body")    // body 。

            var t;
            var arr = new Array();
            for(i=0;i<arrObj.length;i++)    //
            {
                t = arrObj[i], d = 0;
                do
                {
                    if(t.parentNode.getAttribute("id")==id && d == depth)
                    {    
                        arr.push(arrObj[i]);break;        //
                    }
                    else
                    {
                        if(d==depth){break};d+=1;
                    }
                    t = t.parentNode;
                }
                while(t.tagName.toLowerCase()!="body")    // body
            }
            return arr;
        }
    }
}
window.onload = function()
{
    var aa = new opCard();
    aa.bind = ["a1","div","b1","div"];
    aa.style = ["a1_0","a1_1","a1_0"];
    aa.index = 0;
    aa.nesting = [false,true,"",""]
    aa.creat();
    aa =null;

    //  onclick ,
    var bba = new opCard();
    bba.bind = ["a2","li","b2","div"];
    bba.style = ["style1","style2","style3"];
    bba.overStyle = true;
    bba.creat();
    bba = null;

    //  onclick ,
    var bbb = new opCard();
    bbb.bind = ["a3","li","b3","div"];
    bbb.style = ["style1","style2","style3"];
    bbb.overStyle = true;
    bbb.creat();
    bbb = null;

    // onmousover
    var cc = new opCard();
    cc.bind = ["a4","li","b4","div"];
    cc.style = ["style1","style2","style3"];
    cc.overStyle = true;
    cc.overChange = true;
    cc.creat();
    cc = null;

    // auto
    var dd = new opCard();
    dd.bind = ["a5","li","b5","div"];
    dd.style = ["style1","style2","style3"];
    dd.auto = [true, 3000];
    dd.creat();
    dd = null;

    // auto
    var ee = new opCard();
    ee.bind = ["a6","li","b6","div"];
    ee.style = ["style1","style2","style3"];
    ee.auto = [true, 2000];
    ee.overChange = true;
    ee.creat();
    ee = null;

    // auto
    var ff = new opCard();
    ff.bind = ["a7","li","b7","div"];
    ff.style = ["style1","style2","style3"];
    ff.auto = [true, 1000];
    ff.overChange = true;
    ff.overStyle = true;
    ff.creat();
    ff = null;

    //
    var gg = new opCard();
    gg.bind = ["a8","li","b8","div"];
    gg.style = ["style1","style2","style3"];
    gg.overStyle = true;
    gg.menu = true;
    gg.creat();
    gg = null;

    //
    var hh = new opCard();
    hh.bind = ["a9","li","a9","li"];
    hh.style = ["style4","style4","style4"];
    //hh.overStyle = true;
    hh.auto = [true, 1000];
    hh.creat();
    hh = null;
}
</script>
<style type="text/css">
body{font-size:12px; font-family:Verdana," ";}
p,ul{margin:0px; padding:0px;}
td,div{font-size:12px}
.a1_0 {border:1px dotted #3399FF; width:120px; background-color:#f5f5f5; margin:3px; padding:2px 0px; cursor:pointer;}
.a1_1 {border:1px solid #FF9900; width:120px; margin:3px; padding:2px 0px; cursor:pointer;}
.test{text-decoration:underline;}
#b1 div.s{border:1px solid #999999; width:90%; height:500px; margin:3px; padding:10px; overflow-y:auto; line-height:18px;}
#b1 div.s strong{color:#0066FF;}
/* */
.style1{float:left; width:80px; background-color:#f5f5f5; border:1px solid #3399FF; text-align:center; margin-right:2px; list-style-type:none; cursor:pointer;}
.style2{float:left; width:80px; background-color:#f5f5f5; border:1px solid #FF9900; text-align:center; margin-right:2px; list-style-type:none; cursor:pointer;}
.style3{float:left; width:80px; background-color:#f5f5f5; border:1px solid #666666; text-align:center; margin-right:2px; list-style-type:none; cursor:pointer;}
#a2,#a3,#a4,#a5,#a6,#a7,#a8 {height:22px;}
#b2 div,#b3 div,#b4 div,#b5 div,#b6 div,#b7 div{border:1px solid #FF9900; height:100px; width:400px; padding:5px; overflow-y:auto;}
#b8 div{border:1px solid #FF9900; height:20px; width:350px; padding:2px 5px;}
#b8 div a{margin-right:20px;}
.style4{float:left; background-color:#999999; text-align:left; list-style-type:none; padding:2px 5px; color:#FFFFFF;}
</style>
</head>
<body>
<table width="100%" border="0" cellspacing="0" cellpadding="0">
  <tr>
    <td id="a1" width="140" valign="top" align="center">
        <div class="test"> </div>
        <div class="test"> onclick</div>
        <div class="test">onmousover </div>
        <div class="test"> auto</div>
        <div class="test"> </div>
        <div class="test"> </div>
        <div class="test"> </div>
        <div class="test"> </div>
        <div class="test">&nbsp;</div>
        <div class="test">&nbsp;</div>
        <div class="test">&nbsp;</div>
        <div class="test">&nbsp;</div>
    </td>
    <td id="b1" valign="top">
        <div class="s">
             , -_-!!!<br><br>
             , , <br><br>
            <p>
            <strong>obj.bind = ["a1","td","b1","div"];</strong><br>
             id="a1" td , id="b1" div , ?<br>
            td div <br>
            ( , , td &lt;td skip="true"&gt;)<br>
             id="a1" td , , td , nesting<br><br>

            <strong>obj.nesting = [false,true,"",""];</strong><br>
             tag , <br>
             div , div , <br>
             false, true, , <br>
             , getElementsByTagName , <br>
             , <br>
             2 id nesting = [false,true,"","q2"];<br>
             ( )<br><br>

            <strong>obj.index = 0;</strong><br>
             , 0 <br><br>

            <strong>obj.style = ["c1","c2","c3"]</strong><br>
             className:<br>
             className c1<br>
             className c2<br>
             onmouseover className c3<br><br>

            <strong>obj.overStyle = false;</strong><br>
             onmouseover, onmouseout [ ], style[2]<br><br>

            <strong>obj.overChange = false;</strong><br>
             onmouseover, onmouseout <br><br>

            <strong>obj.menu = false;</strong><br>
             <br><br>
            <strong>obj.auto = [false, 1000];</strong><br>
             , ( )<br><br>

            <strong>obj.creat();</strong><br>
             , onclick , obj.creat( )<br>
            
            </p>
        </div>
        <div class="s">
        <!-- onclick , -->
          <div id="a2">
            <ul>
              <li>1</li>
              <li>2</li>
              <li>3</li>
              <li>4</li>
            </ul>
          </div>
          <div id="b2">
            <div> onclick <br> overStyle = true;<br>(over,out , )</div>
            <div>
                var bba = new opCard();<br>
                bba.bind = ["a2","li","b2","div"];<br>
                bba.style = ["style1","style2","style1"];<br>
                bba.overStyle = true;<br>
                bba.creat();<br>
                bba = null;
            </div>
            <div>33333</div>
            <div>4444444</div>
          </div><br>
        <!-- onclick , -->
          <div id="a3">
            <ul>
              <li>1</li>
              <li>2</li>
              <li>3</li>
              <li skip="true">4</li>
            </ul>
          </div>
          <div id="b3">
            <div>
                 skip="true"<br> &lt;li skip="true"&gt;4&lt;/li&gt;<br> 4 <br>
                 ,
            </div>
            <div>222222</div>
            <div>33333</div>
            <div>4444444</div>
          </div>
        </div>
        <div class="s">
        <!--onmousover -->
          <div id="a4">
            <ul>
              <li>1</li>
              <li>2</li>
              <li skip="true">3</li>
              <li>4</li>
            </ul>
          </div>
          <div id="b4">
            <div> onmouseover <br>(over,out )<br> &lt;li skip="true"&gt;3&lt;/li&gt;[ 3 ]<br>overStyle = true;</div>
            <div>
                var cc = new opCard();<br>
                cc.bind = ["a4","li","b4","div"];<br>
                cc.style = ["style1","style2","style1"];<br>
                cc.overStyle = true;<br>
                cc.overChange = true;<br>
                cc.creat();<br>
                cc = null;
            </div>
            <div>33333</div>
            <div>4444444</div>
          </div>
        </div>
        <div class="s">
        <!-- auto -->
          <div id="a5">
            <ul>
              <li>1</li>
              <li>2</li>
              <li>3</li>
              <li>4</li>
            </ul>
          </div>
          <div id="b5">
            <div>1111111<br> 3 </div>
            <div>
                var ee = new opCard();<br>
                ee.bind = ["a6","li","b6","div"];<br>
                ee.style = ["style1","style2","style1"];<br>
                ee.auto = [true, 2000];<br>
                ee.overChange = true;<br>
                ee.creat();<br>
                ee = null;
            </div>
            <div>33333<br> 3 </div>
            <div>4444444<br> 3 </div>
          </div>
          <div> :<strong> </strong><br><br> overChange </div>
          <!-- auto -->
          <div id="a6">
            <ul>
              <li>1</li>
              <li>2</li>
              <li>3</li>
              <li>4</li>
            </ul>
          </div>
          <div id="b6">
            <div>1111111<br> 2 </div>
            <div>
                var dd = new opCard();<br>
                dd.bind = ["a5","li","b5","div"];<br>
                dd.style = ["style1","style2","style1"];<br>
                dd.auto = [true, 3000];<br>
                dd.creat();<br>
                dd = null;<br>
            </div>
            <div>33333<br> 2 </div>
            <div>4444444<br> 2 </div>
          </div>
          <div><br> &lt;li skip="true"&gt;3&lt;/li&gt;, overStyle=true;</div>
          <!-- auto -->
          <div id="a7">
            <ul>
              <li>1</li>
              <li>2</li>
              <li skip="true">3</li>
              <li>4</li>
            </ul>
          </div>
          <div id="b7">
            <div>1111111<br> 1 </div>
            <div>
                var ff = new opCard();<br>
                ff.bind = ["a7","li","b7","div"];<br>
                ff.style = ["style1","style2","style1"];<br>
                ff.auto = [true, 1000];<br>
                ff.overChange = true;<br>
                ff.overStyle = true;<br>
                ff.creat();<br>
                ff = null;
            </div>
            <div>33333<br> 1 </div>
            <div>4444444<br> 1 </div>
          </div>
        </div>
        <!-- -->
        <div class="s">
          <div id="a8">
            <ul>
              <li skip="true"> </li>
              <li> </li>
              <li> </li>
              <li skip="true"> </li>
            </ul>
          </div>
          <div id="b8">
            <div></div>
            <div><a href="#"> </a><a href="#"> </a><a href="#"> </a><a href="#"> </a></div>
            <div><a href="#"> </a><a href="#">blue idea</a></div>
            <div></div>
          </div>
          <div><strong> : </strong><br> , position 。-o-<br> , </div>
        </div>
        <div class="s">
             <br> <br>
             , ,
        </div>
        <!-- -->
        <div class="s">
             , , 。。。<br>
             , 。。
            <div id="a9">
              <li> </li>
              <li> </li>
              <li> </li>
              <li> </li>
              <li> ~! ~! ?</li>
            </div>            

        </div>
        <div class="s">
             ( ) , <br> skip="true", <br>
             <br><br>
             ajax , 。<br>
             , , , <br><br>
             , <br>
             , , , 。<br><br>

             , , <br>
            
        </div>
        <div class="s"> 1</div>
        <div class="s"> 2</div>
        <div class="s"> 3</div>
        <div class="s"> 4</div>
    </td>
  </tr>
</table>
</body>
</html>