功能介绍:
1.鼠标划过当前按钮,当前按钮变色
2.对应图片展示
3.鼠标划过其他按钮,对应图片出现,其他按钮变回原色,其他图片隐藏
所有代码:
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta http-equiv="X-UA-Compatible" content="ie=edge">
<title>选项卡2</title>
<style>
body, div, dl, dt, dd, ul, li, h1, h2, h3, h4, h5, h6, code, form, input, textarea, p, th, td, fieldset, legend, figure {
margin: 0;
padding: 0;
}
body {
font-family: "微软雅黑", Arial;
}
ul, ol {
list-style: none;
}
a {
text-decoration: none;
}
img {
border: 0;
}
.uls1 {
width: 500px;
height: 40px;
background: #2ba0db;
}
.uls1 li {
width: 99px;
height: 40px;
text-align: center;
line-height: 40px;
float: left;
cursor: pointer;
border-right: 1px solid black;
color: white;
}
.box {
width: 500px;
height: 400px;
margin: 100px auto;
position: relative;
}
.uls2 li {
position: absolute;
top: 40px;
}
.uls2 li img {
width: 500px;
height: 400px;
float: left;
}
.cur {
background: #282c34;
}
</style>
<body>
<div class="box">
<ul class="uls1">
<li>1</li>
<li>2</li>
<li>3</li>
<li>4</li>
<li>5</li>
</ul>
<ul class="uls2">
<li><img src="img/1.jpg" alt=""></li>
<li><img src="img/2.jpg" alt=""></li>
<li><img src="img/3.jpg" alt=""></li>
<li><img src="img/4.jpg" alt=""></li>
<li><img src="img/5.jpg" alt=""></li>
</ul>
</div>
</body>
</html>
<script src="js/jquery-1.8.3.min.js"></script>
<script>
var child = $(".uls1").children("li");
var child2 = $(".uls2").children("li");
$(child).mouseover(function () {
$(child).eq($(this).index()).addClass("cur").siblings().removeClass('cur');
$(child2).hide().eq($(this).index()).show();
});
</script>
标签:jquery,40px,选项卡,cur,height,width,按钮,li From: https://blog.51cto.com/u_12422954/5986028