DIV+CSS+JavaScript实现仿dede选项卡tab切换效果,可以自用添加选项卡个数,非常简单易用的代码
CSS代码
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 |
<style type="text/css"> <!-- /*选项卡*/ #Tab1{ width:680px; margin:0px; padding:0px; margin:0 auto;} /*菜单class*/ .Menubox { width:100%; background:url(3.gif); height:28px; line-height:28px; } .Menubox ul{ margin:0px; padding:0px; } .Menubox li{ float:left; display:block; cursor:pointer; width:114px; text-align:center; color:#949694; font-weight:bold; } .Menubox li.hover{ padding:0px; background:#fff; width:116px; border-left:1px solid #A8C29F; border-top:1px solid #A8C29F; border-right:1px solid #A8C29F; background:url(2.gif); color:#739242; font-weight:bold; height:27px; line-height:27px; } .Contentbox{ clear:both; margin-top:0px; border:1px solid #A8C29F; border-top:none; height:181px; text-align:center; padding-top:8px; } --> </style> |
JS代码
1 2 3 4 5 6 7 8 9 10 11 |
<script> <!-- /*更换显示样式*/ function setTab(name,cursel,n){ for(i=1;i<=n;i++){ var menu=document.getElementById(name+i); var con=document.getElementById("con_"+name+"_"+i); menu.className=i==cursel?"hover":""; con.style.display=i==cursel?"block":"none";}} //--> </script> |
html代码
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 |
<div id="Tab1"> <div class="Menubox"> <ul> <li id="one1" onclick="setTab('one',1,4)" class="hover">新闻1</li> <li id="one2" onclick="setTab('one',2,4)" >新闻2</li> <li id="one3" onclick="setTab('one',3,4)">新闻3</li> <li id="one4" onclick="setTab('one',4,4)">新闻4</li> </ul> </div> <div class="Contentbox"> <div id="con_one_1" class="hover"><h3>www.skyfox.org</h3></div> <div id="con_one_2" style="display:none"><h3>skyfox.org</h3></div> <div id="con_one_3" style="display:none"><h3>www.skyfox.org</h3></div> <div id="con_one_4" style="display:none"><h3>skyfox.org</h3></div> </div> </div> |
tab背景 3.gif tabli的hover背景2.gif