html部分代码:
<!doctype html>
<html lang="ch-ZN">
<head><meta charset="UTF-8"><meta name="viewport"content="width=device-width, user-scalable=no, initial-scale=1.0, maximum-scale=1.0, minimum-scale=1.0"><meta http-equiv="X-UA-Compatible" content="ie=edge"><title>jQuery简单实现鼠标经过切换图片特效</title><link rel="stylesheet" href="tb.css"><script src="https://libs.baidu.com/jquery/2.1.4/jquery.min.js"></script>
</head>
<body>
<main class="main"><div class="content pure-g"><ul class="pure-u-1-4"><li><a href="#">高清桂林山水壁纸图片</a></li><li><a href="#">高清阿尔卑斯山壁纸图片</a></li><li><a href="#">青山绿水高清壁纸风景图片</a></li><li><a href="#">好看的海岛唯美风景图片</a></li><li><a href="#">桃花盛开的粉色美景高清壁纸桃花盛开的粉色美景高清壁纸</a></li><li><a href="#">一片草青色的大草原高清壁纸</a></li><li><a href="#">坝上草原高清唯美日落夜景</a></li><li><a href="#">海浪美景高清壁纸欣赏</a></li><li><a href="#">海上的蓝天白云高清壁纸</a></li><li><a href="#">绿油油的竹海美景高清壁纸</a></li></ul><div class="right pure-u-3-4"><div><a href="#"><img src="images/1.jpg" alt=""></a></div><div><a href="#"><img src="images/2.jpg" alt=""></a></div><div><a href="#"><img src="images/3.jpg" alt=""></a></div><div><a href="#"><img src="images/4.jpg" alt=""></a></div><div><a href="#"><img src="images/5.jpg" alt=""></a></div><div><a href="#"><img src="images/6.jpg" alt=""></a></div><div><a href="#"><img src="images/7.jpg" alt=""></a></div><div><a href="#"><img src="images/8.jpg" alt=""></a></div><div><a href="#"><img src="images/9.jpg" alt=""></a></div><div><a href="#"><img src="images/10.jpg" alt=""></a></div></div></div>
</main>
<script>//鼠标经过切换图片特效$(function () {$("ul li").mouseover(function () {//鼠标经过左侧li时var index = $(this).index();//给当前li声明一个index变量$(".right div").eq(index).show();//鼠标经过当前li的时候对应显示右侧对应索引的图片$(".right div").eq(index).siblings().hide();//隐藏其他li对应的图片})})
</script>
</body>
</html>
在页面头部引用了百度的jQuery库,并引用了pure前端框架,并在css代码中进行了引用。Css代码:
@import url(pure.css);
*{margin: 0;padding: 0;box-sizing: border-box;
}
body{font-family: "Microsoft YaHei UI Light";font-size: 16px;color: #666;
}
ul li{list-style: none;
}
a{color: #df5000;text-decoration: none;
}
.main{margin-top: 20px;
}
.content{width: 1024px;height: 360px;margin: 0 auto;padding: 15px;background-color:#dddddd;overflow: hidden;border-radius: 5px;
}
.content ul li{max-width: 100%;margin-right: 5px;padding: 5px;line-height: 24px;counter-increment:number;overflow: hidden;white-space: nowrap;text-overflow: ellipsis;transition: all 0.6s;
}
.content ul li::before{display: inline-block;width: 20px;height: 20px;content: counter(number);margin-right: 5px;
}
.content ul li:nth-child(1)::before{color: rgba(255,0,0,.9);
}
.content ul li:nth-child(2)::before{color: rgba(255,0,0,.6);
}
.content ul li:nth-child(3)::before{color: rgba(255,0,0,.4);
}
.content ul li:hover{background-color: #fff;border-bottom: 1px dashed #000;border-radius: 5px;
}
.content .right{height: 334px;overflow: hidden;
}
.content .right img{display: block;width: 100%;height: 334px;
}
需要将pure.css放在和html同一目录下。以下是效果图: