选项卡的原理很简单,鼠标移上去就让其显示一下的卡片信息
废话不多少,直接上代码
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Document</title>
<style>
* {
margin: 0;
padding: 0;
}
ul,
ol,
li {
list-style: none;
}
.box {
width: 600px;
height: 400px;
border: 10px solid pink;
margin: 50px auto;
}
ul {
width: 100%;
height: 60px;
overflow: hidden;
}
ul>li {
width: 200px;
height: 100%;
text-align: center;
line-height: 60px;
font-size: 40px;
color: #fff;
background-color: skyblue;
cursor: pointer;
float: left;
}
ul>li.active {
background-color: orange;
}
ol {
width: 100%;
height: 340px;
position: relative;
}
ol>li {
width: 100%;
height: 100%;
position: absolute;
left: 0;
top: 0;
background-color: purple;
font-size: 100px;
line-height: 340px;
color: #fff;
text-align: center;
display: none;
}
ol>li.active {
display: block;
}
</style>
</head>
<body>
<div class="box">
<ul>
<li class="active">1</li>
<li>2</li>
<li>3</li>
</ul>
<ol>
<li class="active">1</li>
<li>2</li>
<li>3</li>
</ol>
</div>
<script src="./js/jQuery.min.js"></script>
<script>
$('ul>li').on('mouseover', function() {$(this).addClass('active').siblings().removeClass('active').parent().siblings().children().removeClass('active').eq($(this).index()).addClass('active')})
</script>
</body>
</html>
|