共计 2904 个字符,预计需要花费 8 分钟才能阅读完成。
提醒:本文最后更新于2017-03-28 12:56,文中所关联的信息可能已发生改变,请知悉!
Tab切换的应用,一般通过设置display:none和display:block来实现内容的隐藏和显示。一般习惯管onclick点击实现切换叫做选项卡,onmouseover鼠标经过切换内容叫做滑动门。而想实现TAB的自动循环切换的话,就需要写一段循环控制切换,ScrollTime是控制切换间隔时间的,单位是毫秒,使用时可以酌情设置,一般设置值大概是5000。
<!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" lang="UTF-8"> | |
<head> | |
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" /> | |
<title>自动循环选项卡</title> | |
<style type="text/css"> | |
*{list-style:none;margin:0;padding:0;overflow:hidden} | |
.tab1{width:401px;border-top:#A8C29F solid 1px;border-bottom:#A8C29F solid 1px;margin:50px 200px;} | |
.menu{width:400px;background:#eee;height:28px;border-right:#A8C29F solid 1px;border-bottom:#A8C29F solid 1px;} | |
li{float:left;width:99px;text-align:center;line-height:28px;height:28px;cursor:pointer;border-left:#A8C29F solid 1px;color:#666;font-size:14px;overflow:hidden} | |
.menudiv{width:399px;height:300px;border-left:#A8C29F solid 1px;border-right:#A8C29F solid 1px;border-top:0;background:#fefefe} | |
.menudiv div{padding:15px;line-height:28px;} | |
.off{background:#E0E2EB;color:#336699;font-weight:bold} | |
</style> | |
<script type="text/javascript"> | |
function setTab(name,cursel){ | |
cursel_0=cursel; | |
for(var i=1; i<=links_len; i++){ | |
var menu = document.getElementById(name+i); | |
var menudiv = document.getElementById("con_"+name+"_"+i); | |
if(i==cursel){ | |
menu.className="off"; | |
menudiv.style.display="block"; | |
} | |
else{ | |
menu.className=""; | |
menudiv.style.display="none"; | |
} | |
} | |
} | |
function Next(){ | |
cursel_0++; | |
if (cursel_0>links_len)cursel_0=1 | |
setTab(name_0,cursel_0); | |
} | |
var name_0='one'; | |
var cursel_0=1; | |
var ScrollTime=3000;//循环周期(毫秒) | |
var links_len,iIntervalId; | |
onload=function(){ | |
var links = document.getElementById("tab1").getElementsByTagName('li') | |
links_len=links.length; | |
for(var i=0; i<links_len; i++){ | |
links<span style="text-decoration: line-through;">.onmouseover=function(){ | |
clearInterval(iIntervalId); | |
this.onmouseout=function(){ | |
iIntervalId = setInterval(Next,ScrollTime);; | |
} | |
} | |
} | |
document.getElementById("con_"+name_0+"_"+links_len).parentNode.onmouseover=function(){ | |
clearInterval(iIntervalId); | |
this.onmouseout=function(){ | |
iIntervalId = setInterval(Next,ScrollTime);; | |
} | |
} | |
setTab(name_0,cursel_0); | |
iIntervalId = setInterval(Next,ScrollTime); | |
} | |
</script> | |
</head> | |
<body> | |
<div class="tab1" id="tab1"> | |
<div class="menu"> | |
<ul> | |
<li id="one1" onclick="setTab('one',1)">选项卡1</li> | |
<li id="one2" onclick="setTab('one',2)">选项卡2</li> | |
<li id="one3" onclick="setTab('one',3)">选项卡3</li> | |
<li id="one4" onclick="setTab('one',4)">选项卡4</li> | |
</ul> | |
</div> | |
<div class="menudiv"> | |
<div id="con_one_1"><h4 style="color:red">新闻内容1:</h4><a href="#/">欢迎访问志文工作室! </a></div> | |
<div id="con_one_2" style="display:none;"><h4 style="color:red">新闻内容2:</h4><a href="#">计算机技术学习网:http://lzw.me</a></div> | |
<div id="con_one_3" style="display:none;"><h4 style="color:red">内容3:</h4><a href="#">ASP.NET学习 http://lzw.me/aspx/</a></div> | |
<div id="con_one_4" style="display:none;"><h4 style="color:red">新闻4-</h4><a href="#">致力于CSS学习,前端技术,浏览器兼容,W3C标准,网页重构的研究和讨论</a></div> | |
</div> | |
</div> | |
</body> | |
</html> |
正文完