分享好友 教程首页 教程搜索 频道列表

多功能选项卡切换效果

2019-02-25 10:547020
+关注29
核心提示:效果图HTMLdiv id="box"div id="tab"ulli class="on"选项卡一/lili选项卡二/lili选...


效果图


HTML


<div id="box">
    <div id="tab">
        <ul>
            <li class="on">选项卡一</li>
            <li>选项卡二</li>
            <li>选项卡三</li>
            <li>选项卡四</li>
        </ul>
    </div>
    <div id="content">
        <div class="pic on">
            <ul>
                <li class="on" style="background: url(http://www.jq22.com/img/cs/500x500-1.png);"></li>
                <li style="background: url(http://www.jq22.com/img/cs/500x500-2.png);"></li>
                <li style="background: url(http://www.jq22.com/img/cs/500x500-3.png);"></li>
                <li style="background: url(http://www.jq22.com/img/cs/500x500-4.png);"></li>
            </ul>
        </div>
        <div class="btn on">
            <ul>
                <li class="on">1</li>
                <li>2</li>
                <li>3</li>
                <li>4</li>
            </ul>
        </div>

        <div class="pic">
            <ul>
                <li class="on" style="background: url(http://www.jq22.com/img/cs/500x500-5.png);"></li>
                <li style="background: url(http://www.jq22.com/img/cs/500x500-6.png);"></li>
                <li style="background: url(http://www.jq22.com/img/cs/500x500-7.png);"></li>
                <li style="background: url(http://www.jq22.com/img/cs/500x500-8.png);"></li>
                <li style="background: url(http://www.jq22.com/img/cs/500x500-9.png);"></li>
            </ul>
        </div>
        <div class="btn">
            <ul>
                <li class="on">1</li>
                <li>2</li>
                <li>3</li>
                <li>4</li>
                <li>5</li>
            </ul>
        </div>

        <div class="pic">
            <ul>
                <li class="on" style="background: url(http://www.jq22.com/img/cs/500x300-1.png);"></li>
                <li style="background: url(http://www.jq22.com/img/cs/500x300-2.png);"></li>
                <li style="background: url(http://www.jq22.com/img/cs/500x300-3.png);"></li>
                <li style="background: url(http://www.jq22.com/img/cs/500x300-4.png);"></li>
            </ul>
        </div>
        <div class="btn">
            <ul>
                <li class="on">1</li>
                <li>2</li>
                <li>3</li>
                <li>4</li>
            </ul>
        </div>

        <div class="pic">
            <ul>
                <li class="on" style="background: url(http://www.jq22.com/img/cs/500x300-5.png);"></li>
                <li style="background: url(http://www.jq22.com/img/cs/500x300-6.png);"></li>
                <li style="background: url(http://www.jq22.com/img/cs/500x300-7.png);"></li>
                <li style="background: url(http://www.jq22.com/img/cs/500x300-8.png);"></li>
                <li style="background: url(http://www.jq22.com/img/cs/500x300-9.png);"></li>
            </ul>
        </div>
        <div class="btn">
            <ul>
                <li class="on">1</li>
                <li>2</li>
                <li>3</li>
                <li>4</li>
                <li>5</li>
            </ul>
        </div>
    </div></div>

CSS


* {
	margin:0;
	padding:0;
	font-family:Microsoft YaHei,serif;
}
li {
	list-style:none;
}
#box {
	width:426px;
	height:104px;
	margin:50px auto;
}
#tab {
	width:100px;
	height:100%;
	float:left;
}
#tab ul li {
	width:100px;
	height:50px;
	margin-bottom:1px;
	background:#000;
	font-size:18px;
	text-align:center;
	line-height:50px;
	color:#fff;
	cursor:default;
}
#tab ul li.on {
	background:#f60;
}
#content {
	position:relative;
	width:326px;
	height:203px;
	float:right;
}
#content .pic {
	display:none;
}
#content .pic.on {
	display:block;
}
#content .pic ul li {
	display:none;
	width:100%;
	height:203px;
	cursor:default;
}
#content .pic ul li.on {
	display:block;
}
#content .btn {
	display:none;
	position:absolute;
	bottom:0;
	right:0;
	height:35px;
	width:100%;
	background:rgba(0,0,0,.5);
}
#content .btn.on {
	display:block;
}
#content .btn ul {
	float:right;
}
#content .btn ul li {
	float:left;
	width:35px;
	height:35px;
	background:#ddd;
	text-align:center;
	line-height:35px;
	margin-left:2px;
}
#content .btn ul li.on {
	background:#f60;
}

JS


var tabLi = document.querySelectorAll("#tab li"),
    pic = document.getElementsByClassName("pic"),
    btn = document.getElementsByClassName("btn"),
    index = 0;

for (var i = 0; i < tabLi.length; i++) {
    var picLi = pic[i].querySelectorAll("li"),
        btnLi = btn[i].querySelectorAll("li");
    (function(i) {
        tabLi[i].onmouseenter = function() {
            tabLi[index].className = '';
            pic[index].className = "pic";
            btn[index].className = "btn";
            index = i;
            tabLi[i].className = 'on';
            pic[i].className = "pic on";
            btn[i].className = "btn on";
        }
    })(i);

    (function(pLi, bLi) {
        var index = 0;
        for (var i = 0; i < bLi.length; i++) {
            (function(i) {
                bLi[i].onmouseenter = function() {
                    bLi[index].className = "";
                    pLi[index].className = "";
                    index = i;
                    bLi[i].className = "on";
                    pLi[i].className = "on";
                }
            }(i))
        }
    }(picLi, btnLi))
}

提示: jQuery调用版本:1.11.3

本文标签: #选项卡 #切换
免责声明:凡注明来源本网的所有作品,均为本网合法拥有版权或有权使用的作品,欢迎转载,注明出处。非本网作品均来自互联网,转载目的在于传递更多信息,并不代表本网赞同其观点和对其真实性负责。
生成海报
您可能在找更多

基于swiper的Tab选项卡

    选项卡五花八门,今天又要用到选项卡,首选swiper!一、HTML布局根据swiper官网的要求来class命名滑块。divclass=boxulclass=swiperTablispanDiv+CSS/span/lilispanJavaScript+JQuery/span/lilispanAngularJS+Vue+No

小黑 web前端开发2021-06-19

tab选项卡切换

    效果图HTMLdiv class="box"ul class="menu"li历史/lili文学/lili宗教/li/ulul class="list"li style="background: red"1/lili style="background: black"2/lili style="background: purple"3/li/ul/divCSS * {margin:0;p

小黑 JS相关2019-02-25

JS下划线跟随tab选项卡

    效果图 HTMLdiv class="nav"ullidon(0)"翠翠/lilidon(1)"嗯嗯/lilidon(2)"小白/lilidon(3)"小沫/lilidon(4)"同同/li/ul/divdiv class="tiao"div id="zhou" class="zhou" style="left: 0;"div class="ww&

小黑 JS相关2019-02-25

简洁的jQuery选项卡(Tab页签)插件

    一个很简洁的jQuery选项卡插件,只要你不是前端傻子,看一会儿就能明白怎么使用的。这个效果很赞的,可以作鼠标经过切换,也可以作鼠标点击切换。关键是可以无限重复使用,稍作修改,也可以作嵌套Tab页签效果。属于必须收藏的那种效果!不再啰嗦,下面可能是你不常看到如此简洁干净的demo了。简洁的jQuery选项卡(Tab页签)插件 Demo!DOCTYPE htmlhtml lang="en"headmeta http-equiv="Content-Type" conte

小黑 网页特效2018-09-03

下一篇
我来说两句
抢沙发