功能介紹:
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>複製程式碼