<html>
<head>
<meta charset=" utf-8">
<title>tab切换</title>
<style type="text/css">
body,h2,p{
margin:0px;
padding:0px;
}ul,li{
margin:0px;
padding:0px;
float:left;
list-style-type:none;
}
body{font-size:12px;}
.box{
width:722px;
height:99px;
margin:10px auto;
border:1px solid #dedede;
}
.list{
width:711px;
height:22px;
float:left;
padding:4px 0 0 9px;
border-top:1px solid #fff;
border-left:1px solid #fff;
border-right:1px solid #fff;
}
.list li{
width:74px;
height:22px;
float:left;
cursor:pointer;
color:#656565;
line-height:22px;
text-align:center;
}
.list li.hove{
width:72px;
height:20px;
color:#fc6703;
line-height:20px;
border-top:1px solid #dedede;
border-left:1px solid #dedede;
border-right:1px solid #dedede;
border-bottom:1px solid #fff;
background:#fff;
}
.content{
width:722px;
height:72px;
float:left;
display:none;
}
</style>
<script>
function $(id){
return typeof id === "string" ? document.getElementById(id) : id;
}
function $$(oParent, elem){
return (oParent || document).getElementsByTagName(elem);
}
function $$$(oParent, sClass){
var aElem = $$(oParent, '*');
var aClass = [];
var index = 0;
for(index=0;index<aElem.length;index++){
if(aElem[index].className == sClass){
aClass.push(aElem[index]);
}
}
return aClass;
}
function addEvent(oElm, strEvent, fuc) {
addEventListener?oElm.addEventListener(strEvent,fuc,false):oElm.attachEvent('on'+strEvent,fuc);
};
function Tab(){
this.initialize.apply(this, arguments);
}
Object.extend = function(destination, source) {
for (var property in source) {
destination[property] = source[property];
}
return destination;
};
Tab.prototype = {
initialize : function(obj, dis, content, onEnd, eq){
this.obj = $(obj);
this.oList = $$$(this.obj, 'list')[0];
this.aCont = $$$(this.obj, content);
this.oUl = $$(this.oList, 'ul')[0];
this.aLi = this.oUl.children;
this.timer = null;
eq ? (this.aLi.length < eq ? eq = 0 : eq) : eq = 0;
this.oEve(onEnd);
this.onEnd.method == 'mouseover' ? this.method = "mouseover" : this.method = "click";
this.onEnd.autoplay == 'stop' ? this.autoplay = "stop" : this.autoplay = "play";
this.aCont[eq].style.display = 'block';
this.aLi[eq].className = 'hove';
this.display(dis);
this.autoPlayTab(eq, dis);
},
oEve: function(onEnd){
this.onEnd = {
method: 'mouseover',
autoplay: 'stop',
};
Object.extend(this.onEnd, onEnd || {});
},
display : function(dis){
var _this = this;
var index = iNow = 0;
for(index=0;index<_this.aLi.length;index++){
(function(){
var j = index;
addEvent(_this.aLi[j], _this.method,
function() {
_this.fnClick(j,dis);
_this.autoPlayTab(j, dis);
})
})()
}
},
autoPlayTab : function(iNow, dis){
if(this.autoplay == 'play'){
var _this = this;
this.iNow = iNow;
this.obj.onmouseover = function(){
clearInterval(_this.timer);
};
this.obj.onmouseout = function(){
_this.timer = setInterval(playTab,5000);
};
clearInterval(_this.timer);
_this.timer = setInterval(playTab,5000);
function playTab(){
if(_this.iNow == _this.aLi.length)_this.iNow = 0;
_this.fnClick(_this.iNow, dis)
_this.iNow++
}
}
},
fnClick : function(oBtn, dis){
var index = 0;
for(index=0;index<this.aLi.length;index++){
this.aLi[index].className = '';
this.aCont[index].style.display = 'none';
}
this.aLi[oBtn].className = dis;
this.aCont[oBtn].style.display = 'block';
}
};
window.onload = function(){
new Tab("box", 'hove', 'content', {
method : 'mouseover',
autoplay : 'play'
},0);
};
</script>
</head>
<body>
<div id="box" class="box">
<div class="list">
<ul>
<li>div教程</li>
<li>jquery教程</li>
<li>css教程</li>
</ul>
</div>
<div class="content">蚂蚁部落欢迎您</div>
<div class="content">本站url地址是softwhy.com</div>
<div class="content">只有努力才会有美好的未来</div>
</div>
</body>
</html>
function $$$(oParent, sClass){
var aElem = $$(oParent, '*');
var aClass = [];
var index = 0;
for(index=0;index<aElem.length;index++){
if(aElem[index].className == sClass){
aClass.push(aElem[index]);
}
}
return aClass;
}
.function addEvent(oElm, strEvent, fuc) {
addEventListener?oElm.addEventListener(strEvent,fuc,false) : oElm.attachEvent('on'+strEvent,fuc);
}
function Tab(){ this.initialize.apply(this, arguments);
}
Object.extend = function(destination, source) {
for (var property in source) {
destination[property] = source[property];
}
return destination;
}
oEve: function(onEnd){
this.onEnd = {
method: 'mouseover',
autoplay: 'stop',
};
Object.extend(this.onEnd, onEnd || {});
}
this.onEnd = {
method: 'mouseover',
autoplay: 'stop',
}
Object.extend(this.onEnd, onEnd || {})
.(function(){ var j = index;
addEvent(_this.aLi[j], _this.method,
function() {
_this.fnClick(j,dis);
_this.autoPlayTab(j, dis);
})
})()
this.obj.onmouseout = function(){
_this.timer = setInterval(playTab,5000);
}
function playTab(){
if(_this.iNow == _this.aLi.length)_this.iNow = 0;
_this.fnClick(_this.iNow, dis)
_this.iNow++
}
.fnClick : function(oBtn, dis){
var index = 0;
for(index=0;index<this.aLi.length;index++){
this.aLi[index].className = '';
this.aCont[index].style.display = 'none';
}
this.aLi[oBtn].className = dis;
this.aCont[oBtn].style.display = 'block';
}
机械节能产品生产企业官网模板...
大气智能家居家具装修装饰类企业通用网站模板...
礼品公司网站模板
宽屏简约大气婚纱摄影影楼模板...
蓝白WAP手机综合医院类整站源码(独立后台)...苏ICP备2024110244号-2 苏公网安备32050702011978号 增值电信业务经营许可证编号:苏B2-20251499 | Copyright 2018 - 2025 源码网商城 (www.ymwmall.com) 版权所有