var controlList = $('.control-list-item');
var contentList = $('.content-list-item');
controlList.click(function(event) {
var index = $(this).index();
$(this).addClass('active').siblings().removeClass('active');
contentList.eq(index).slideDown('slow').siblings().slideUp('fast');
});
选项卡效果
直接上代码
<!DOCTYPE html>
<html>
<head>
<script type="text/javascript" >
});
</script>
.tab{width: 250px;background-color: red}
.none{display: none;}
.red{background-color: red;}
</head>
<body>
<p class="tab">
</body>
</html>
要么用插件Jquery UI 要么自己写纯生js
像这种mouseover直接改变css样式就好了。
这就是个选项卡的效果,其实呢这里面的内容都全部加载在这个页面了,只不过是默认显示一个其他的都隐藏掉了,然后呢,绑定事件来控制相应的显示跟隐藏。其实你可以自己定一个类名,比如 .hd{display:none};通过添加跟移除这个类名来控制所选内容的显示跟隐藏。
除了楼上的用法,用css3新特性也是很好的,比如target之类的
https://jqueryui.com/ jquery ui - tab
http://gaoqiang19514.github.io/demoPage/
结构进页面去看,js代码就这些OK
// tab
(function(){
})();