关注前端开发
关注用户体验

三种简洁的Tab导航(选项卡)

在网页中应用选项卡可以使网页显得更紧凑,结合AJAX技术可以使页面在有限的空间内展现更多的内容。本文主要介绍几种简洁的选项卡效果的实现(不 涉及滑动门和AJAX),附有实例,无图片,兼容性较好,方便大家直接使用。

第一种形式: 通过更换显示样式实现,这种很常见,就不多说了。

CODE:

<div id=”tabs0″>

<ul id=”menu0″>

<li onclick=”setTab(0,0)” <li onclick=”setTab(0,1)”& gt;评论</li>

<li onclick=”setTab(0,2)”>技术</li& gt;

<li onclick=”setTab(0,3)”>点评</li>

</ul>

<div id=”main0″>

<ul <ul><li>评论列表</li></ul>

<ul><li>技术列表</li></ul>

<ul><li>点评列表</li></ul>

</div>

</div>

第 二种形式: 这种结构比较复杂一些,外面加一个相对层(.menu1box),设置溢出隐藏,将选项卡(#menu1)设为绝对定位,设置层指针为1(z- index:1;),以便可以遮住下主区块(.main1box)1px的高度。设置主区块的边框为1px的黑边,上空白(margin-top)为 -1px,使上边框伸到选项卡下。当改变选项卡某项(li)的背景为白色时便可遮住一部分主区块的上边框。这样效果就实现了。

CODE:

<div id=”tabs1″>

<div <ul id=”menu1″>

<li onmouseover=”setTab(1,0)”><a href=”#” mce_href=”#”>新闻</a></li>

<li onmouseover=”setTab(1,1)”><a href=”#” mce_href=”#”>评论</a></li>

<li onmouseover=”setTab(1,2)”><a href=”#” mce_href=”#”>技术</a></li>

<li onmouseover=”setTab(1,3)”><a href=”#” mce_href=”#”>点评</a></li>

</ul>

</div>

<div <div id=”main1″>

<ul <ul><li>评论列表</li></ul>

<ul><li>技术列表</li></ul>

<ul><li>点评列表</li></ul>

</div>

</div>

</div>

第 一、二种形式的JS代码:

CODE:

function setTab(m,n){

var tli=document.getElementById(”menu”+m).getElementsByTagName(”li”); /*获取选项卡的LI对象*/

var mli=document.getElementById(”main”+m).getElementsByTagName(”ul”); /*获取主显示区域对象*/

for(i=0;i<tli.length;i++){

tli[i].className=i==n?”hover”:””; /*更改选项卡的LI对象的样式,如果是选定的项则使用.hover样式*/

mli[i].style.display=i==n?”block”:”none”; /*确定主区域显示哪一个对象*/

}

}

第 三种形式: 这也是一种不常用的方式,加一个相对层(.menu2box),利用一个背景层(#tip2)定位,通过改变层的左距离(left)实现效果。

CODE:

<div id=”tabs2″>

<div <div id=”tip2″></div>

<ul id=”menu2″>

<li onmouseover=”nowtab(2,0)”><a href=”#” mce_href=”#”>新闻</a></li>

<li onmouseover=”nowtab(2,1)”><a href=”#” mce_href=”#”>评论</a></li>

<li onmouseover=”nowtab(2,2)”><a href=”#” mce_href=”#”>技术</a></li>

<li onmouseover=”nowtab(2,3)”><a href=”#” mce_href=”#”>点评</a></li>

</ul>

</div>

<div id=”main2″>

新闻内容

</div>

</div>

赞(1)
未经允许不得转载:大前端 » 三种简洁的Tab导航(选项卡)
分享到: 更多 (0)

评论 8

  • 昵称 (必填)
  • 邮箱 (必填)
  • 网址
  1. #8

    Wonderful, what a weblog it is! This blog presents valuable data to us, keep it up.

  2. #7

    Good blog, I’m going to spend more time learning about this subject

    Nonton Anime2周前 (05-10)回复
  3. #6

    This blog really is good. How was it made ?

    cat3周前 (05-09)回复
  4. #5

    When I originally commented I clicked the -Notify me when new surveys are added- checkbox and from now on whenever a comment is added I am four emails sticking with the same comment. Perhaps there is any way you can get rid of me from that service? Thanks!

    Loise Rennaker2个月前 (04-08)回复
  5. #4

    A motivating discussion is worth comment. I do think that you ought to publish more about this issue, it may not be a taboo matter but usually people don’t speak about these issues. To the next! All the best!!

    DMC52个月前 (03-31)回复
  6. #3

    This article was written by a real thinking writer. I agree many of the with the solid points made by the writer. I’ll be back.

    my singing monsters2个月前 (03-28)回复
  7. #2

    The the very next time I read a blog, I hope who’s doesnt disappoint me up to this. I mean, I know it was my solution to read, but I actually thought youd have something fascinating to express. All I hear can be a lot of whining about something that you could fix should you werent too busy interested in attention.

    Giuseppe Neher3个月前 (03-11)回复
  8. #1

    那代码呢?或者是用什么插件

    灿22年前 (2017-01-09)回复

themebetter 国内更好的WordPress主题服务商

立即前往