频道栏目
首页 > 资讯 > HTML/CSS > 正文

京东轮播:选项卡里套选项卡

17-01-12        来源:[db:作者]  
收藏   我要投稿

HTML

<!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">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>无标题文档</title>
</head>
<body>
<div id="tab">
    <ul class="title">
    </ul>
    <div class="content">
        <div class="main">
            <img>
            <ul>
            </ul>
        </div>
    </div>
</div>
</body>
</html>

CSS

* {
	margin: 0;
	padding: 0;
}

ul {
	list-style: none;
}

img {
	border: 0;
}

#tab {
	width: 1000px;
	height: 500px;
	margin: 50px auto;
}

#tab .title {
	width: 200px;
	height: 500px;
	display: inline-block;
}

#tab .title li {
	width: 200px;
	height: 125px;
	float: left;
	line-height: 125px;
	text-align: center;
	font-size: 30px;
	background: #f1f1f1;
	border-bottom: 1px dotted #000;
}

#tab .title li.active {
	background: #fff;
}

#tab .title li:hover {
	background: #fff;
}

#tab .content {
	width: 799px;
	height: 500px;
	float: right;
	display: inline-block;
	position: relative;
	border: none;
	border: none;
}

#tab .content img {
	position: absolute;
	top: 0;
	left: 0;
	width: 799px;
	height: 500px;
}

#tab .content ul {
	position: absolute;
	width: 799px;
	height: 45px;
	bottom: 0;
	left: 0;
	filter(alpha: 80);
	opacity: 0.8;
	background: #000;
}

#tab .content ul li {
	float: left;
	height: 45px;
	line-height: 45px;
	background: #d5d5d5;
	border-right: 1px solid #fff;
	cursor: pointer;
	text-align: center;
}

#tab .content ul li.active {
	background: red;
}

#tab .content ul li:hover {
	background: red;
}

JavaScript

window.onload = function() {
    var tab = document.getElementById('tab');
    var title = tab.getElementsByClassName('title')[0];
    var titleLi = title.getElementsByTagName('li');
    var main = tab.getElementsByClassName('main')[0];
    var img = main.getElementsByTagName('img')[0];
    var ul = main.getElementsByTagName('ul')[0];
    var subtitleLi = ul.getElementsByTagName('li');
    var arr = [{
        title: '最热团购',
        subtitle: ['最热团购1', '最热团购2', '最热团购3'],
        pic: ['img/tab/1-1.png', 'img/tab/1-2.png', 'img/tab/1-3.png']
    },
    {
        title: '商城特惠',
        subtitle: ['商城特惠1', '商城特惠2', '商城特惠3', '商城特惠4'],
        pic: ['img/tab/2-1.png', 'img/tab/2-2.png', 'img/tab/2-3.png', 'img/tab/2-4.png']
    },
    {
        title: '名品推荐',
        subtitle: ['名品推荐1', '名品推荐2', '名品推荐3', '名品推荐4', '名品推荐5'],
        pic: ['img/tab/3-1.png', 'img/tab/3-2.png', 'img/tab/3-3.png', 'img/tab/3-4.png', 'img/tab/3-5.png']
    },
    {
        title: '缤纷活动',
        subtitle: ['缤纷活动1', '缤纷活动2', '缤纷活动3', '缤纷活动4'],
        pic: ['img/tab/4-1.png', 'img/tab/4-2.png', 'img/tab/4-3.png', 'img/tab/4-3.png', ]
    }];

    // 初始化
    for (var i = 0; i < arr.length; i++) {
        // 大选项卡的标题
        var oLi = document.createElement('li');
        oLi.innerHTML = arr[i].title;
        oLi.index = i;
        oLi.onclick = function() {
            highlight(this);
            ul.innerHTML = '';
            changeTab(this.index);
        }
        title.appendChild(oLi);
    }
    changeTab(0);
    function changeTab(num) {
        // 大选项卡的内容
        img.src = arr[num].pic[1];
        // 小标题
        for (var j = 0; j < arr[num].subtitle.length; j++) {
            oLi = document.createElement('li');
            oLi.innerHTML = arr[num].subtitle[j];
            oLi.style.width = Math.floor(parseInt(800 / arr[num].subtitle.length) - 2) + 'px';
            oLi.index = j;
            oLi.onclick = function() {
                highlight(this);
                this.parentNode.previousElementSibling.src = arr[num].pic[this.index];
            }
            ul.appendChild(oLi);
        }
    }
    function highlight(ele) {
        var aLi = ele.parentNode.children;
        for (var i = 0; i < aLi.length; i++) {
            aLi[i].className = '';
        }
        ele.className = 'active';
    }
}
这里写图片描述
相关TAG标签
上一篇:提交APP到AppStore审核:No suitable application records were found.
下一篇:编译内核出现"make CONFIG_DEBUG_SECTION_MISMATCH=y"错误
相关文章
图文推荐

关于我们 | 联系我们 | 广告服务 | 投资合作 | 版权申明 | 在线帮助 | 网站地图 | 作品发布 | Vip技术培训 | 举报中心

版权所有: 红黑联盟--致力于做实用的IT技术学习网站