本文发布于:2009-05-12,最后更新于:2017-03-28,如果内容失效请留言告知。
Tab切换的应用,一般通过设置display:none和display:block来实现内容的隐藏和显示。一般习惯管onclick点击实现切换叫做选项卡,onmouseover鼠标经过切换内容叫做滑动门。而想实现TAB的自动循环切换的话,就需要写一段循环控制切换,ScrollTime是控制切换间隔时间的,单位是毫秒,使用时可以酌情设置,一般设置值大概是5000。
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 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 | <! DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> < 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 > |