DIV+CSS滑动门效果

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312" />
<title>无标题文档</title>
<style>
*{ margin:0; padding:0;}
ul{ list-style:none}
body{ font-size:12px}
#tabMenus{ width:400px; margin:100px auto 0 auto;overflow:hidden; border:#ccc solid 1px; border-bottom:none;}
#tabMenus li{ float:left; width:100px; height:25px; line-height:25px; background:#ccc; text-align:center}
#tabMenus li a{ display:block; height:100%; color:#000000; text-decoration:none}
#tabMenus li.current{background:#fff}
#tabMenus li.usual{background:#ccc;}
#tabCons{ clear:both;width:400px; margin:0 auto; overflow:hidden; border:#ccc solid 1px; border-top:none}
#tabCons .con{ float:left; padding:10px; width:380px; display:none}
</style>
<script>
function tab(menus,cons,openClass,closeClass,speed){
   var count = menus.length; //选项的个数。
   var now=1;                //记录当前滑过的选项。
   var timer=null;           //
  
   var clearOpenClass = function(){//清除滑过样式。
   for(var i = 0 ; i < count; i++)
                  {
   menus[i].className = closeClass;                                         
                    cons[i].style.display = "none";
                  }
   };
  
   var changeTab = function(v){//添加滑过样式以及内容切换。
                  clearOpenClass();
menus[v].className = openClass;
cons[v].style.display = "block";
now= v+1;
   };


   var autoChange = function (){//自动切换
     if(now<count){
changeTab(now);
}else{
now = 0;
changeTab(now);
     }
    };

var setAuto = function (){timer = setInterval(autoChange, speed)};
        var clearAuto = function (){clearInterval(timer)};   

    this.init = function(){//初始化。
              if(menus.length != cons.length){ return;}
              clearOpenClass();
      for(var i = 0 ; i < count; i++){
         menus[i].value = i;                             
                  }
menus[0].className='current';
       cons[0].style.display = "block";
   };
  
   this.autoAction = function(){//自动切换时的动作。
           setAuto();
     for(var i = 0 ; i < count; i++){                            
                     menus[i].onmouseover = function(){clearAuto();changeTab(this.value);};
                 menus[i].onmouseout = function(){setAuto();};
}
       };
  
   this.usualAction = function(){//普通切换时的动作。
     for(var i = 0 ; i < count; i++){                            
                     menus[i].onmouseover = function(){changeTab(this.value);};
}
       };

};
tab.prototype = {
       usual : function(){
   this.init();
   this.usualAction();                            
       },
   auto : function(){
   this.init();
   this.autoAction();                           
   }
         
}
function $(id){return document.getElementById(id);}
window.οnlοad=function(){
var menus=$('tabMenus').getElementsByTagName('li');
var cons=$('tabCons').getElementsByTagName('div');
var t=new tab(menus,cons,'current','usual',2000);
t.auto();
}
</script>
</head>
<body>
<ul id="tabMenus">
<li><a href="#">1111</a></li>
<li><a href="#">2222</a></li>
<li><a href="#">3333</a></li>
<li><a href="#">4444</a></li>
</ul>
<div id="tabCons">
<div class="con">1111</div>
<div class="con">2222</div>
<div class="con">3333</div>
<div class="con">4444</div>
</div>

</body>
</html>
把这代码复制放到文本中。然后保存成.html格式。在浏览器中打开即可看效果!

转载于:https://www.cnblogs.com/cbboys/p/3641315.html

body{ color: #000; font-family: "宋体", arial; font-size: 12px; background: #fff; text-align: center; margin: 0; } .nTab{ float: left; width: 240px; margin: 0 auto; border-bottom:1px #C7C7CD solid; background:#d5d5d5; background-position:left; background-repeat:repeat-y; margin-bottom:2px; } .nTab .TabTitle{ clear: both; height: 26px; overflow: hidden; } .nTab .TabTitle ul{ margin:0; padding:0; } .nTab .TabTitle li{ float: left; width: 60px; cursor: pointer; padding-top: 6px; padding-right: 0px; padding-left: 0px; padding-bottom: 7px; list-style-type: none; } .nTab .TabTitle .active{ background:url(images/finance_nc_080124_ws_001.gif) left -25px no-repeat;border-left:1px #C7C7CD solid;border-top:1px #C7C7CD solid;border-bottom:1px #fff solid;} .nTab .TabTitle .normal{ background:url(images/finance_nc_080124_ws_001.gif);border-top:1px #C7C7CD solid;border-bottom:1px #C7C7CD solid;} .nTab .TabContent{ width:auto;background:#fff; margin: 0px auto; padding:10px 0 0 0; border-right:1px #C7C7CD solid;border-left:1px #C7C7CD solid; } .none {display:none;} function nTabs(thisObj,Num){ if(thisObj.className == "active")return; var tabObj = thisObj.parentNode.id; var tabList = document.getElementById(tabObj).getElementsByTagName("li"); for(i=0; i <tabList.length; i++) { if (i == Num) { thisObj.className = "active"; document.getElementById(tabObj+"_Content"+i).style.display = "block"; }else{ tabList[i].className = "normal"; document.getElementById(tabObj+"_Content"+i).style.display = "none"; } } } 预拔电杆 预等电杆 普拔电杆 部预电杆 欢迎访问:阿里西西WEB开发 计源论坛 计源论坛 计源论坛22 计源论坛33
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值