<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Title</title>
<script type="text/javascript" src="../js/tabs_function.js"></script>
<script type="text/javascript">
window.onload = function main() {
Tabs(".list-item", ".contents", "list-item-checked", "contents-checked");
}
</script>
<style type="text/css">
#list-title {
width: 318px;
height: 56px;
margin: 0;
list-style-type: none;
padding-left: 0;
}
.list-item {
float: left;
width: 100px;
height: 50px;
margin: 2px;
line-height: 50px;
font-size: 28px;
text-align: center;
border: 1px solid #000;
cursor: pointer;
}
.list-item-checked {
background-color: #70adff;
color: #ffffff;
}
#content-box {
position: relative;
clear: both;
width: 314px;
height: 302px;
margin: 0 2px;
}
.contents {
position: absolute;
left: 0;
top: 0;
width: 312px;
height: 300px;
margin: 0;
font-size: 32px;
line-height: 300px;
text-align: center;
border: 1px solid #000;
z-index: 0;
opacity: 0;
visibility: hidden;
-webkit-transition: all .5s;
-moz-transition: all .5s;
-ms-transition: all .5s;
-o-transition: all .5s;
transition: all .5s;
}
.contents-checked {
z-index: 1;
opacity: 1;
visibility: visible;
}
</style>
</head>
<body>
<ul id="list-title">
<li class="list-item list-item-checked">1</li>
<li class="list-item">2</li>
<li class="list-item">3</li>
</ul>
<div id="content-box">
<div class="contents contents-checked" style="background-color: #c8ff40;">content_1</div>
<div class="contents" style="background-color: #41ff6f;">content_2</div>
<div class="contents" style="background-color: #ff82a0;">content_3</div>
</div>
</body>
</html>
/**
* Created by Administrator on 2016/9/12.
*/
/*
* tabs_name:用于触发事件的标签的类名;
* contents_name:内容容器的类名;
* tabs_checked_style:标签为选中状态时的样式;
* contents_checked_style:内容容器为选中状态时的样式;
*
* classList.toggle();
* 检查元素的类名列表中是否有指定的类名,如果有则移除,如果没有则添加;
* */
function Tabs(tabs_name, contents_name, tabs_checked_style, contents_checked_style) {
var tabs = document.querySelectorAll(tabs_name),
contents = document.querySelectorAll(contents_name),
e_mark = 0;
for (var i = 0, len = tabs.length; i < len; i++) {
tabs[i].num = i;
tabs[i].onclick = function () {
tabs[e_mark].classList.toggle(tabs_checked_style);
tabs[this.num].classList.toggle(tabs_checked_style);
contents[e_mark].classList.toggle(contents_checked_style);
contents[this.num].classList.toggle(contents_checked_style);
e_mark = this.num;
};
}
}
.list-item {
float: left;
width: 100px;
height: 50px;
margin: 2px;
line-height: 50px;
font-size: 28px;
text-align: center;
border: 1px solid #000;
cursor: pointer;
}
.list-item-checked {
background-color: #70adff;
color: #ffffff;
}
element.classList.add("class-name"); // 字符串
element.classList.add(class_name); // 变量
element.classList.remove(class_name);
element.classList.contains(class_name); // true,false
element.classList.toggle(class_name); // 有则删,无则添;
e_mark = 0;
for (var i = 0, len = tabs.length; i < len; i++) {
tabs[i].num = i;
tabs[i].onclick = function () {
tabs[e_mark].classList.toggle(tabs_checked_style);
tabs[this.num].classList.toggle(tabs_checked_style);
contents[e_mark].classList.toggle(contents_checked_style);
contents[this.num].classList.toggle(contents_checked_style);
e_mark = this.num;
};
}
e_mark = 0;
tabs[i].num = i;
tabs[e_mark].classList.toggle(tabs_checked_style); tabs[this.num].classList.toggle(tabs_checked_style);
机械节能产品生产企业官网模板...
大气智能家居家具装修装饰类企业通用网站模板...
礼品公司网站模板
宽屏简约大气婚纱摄影影楼模板...
蓝白WAP手机综合医院类整站源码(独立后台)...苏ICP备2024110244号-2 苏公网安备32050702011978号 增值电信业务经营许可证编号:苏B2-20251499 | Copyright 2018 - 2025 源码网商城 (www.ymwmall.com) 版权所有