query实现鼠标移动/移过到商品小图片上时替换掉大图片上的图片
1 . 实现效果
2 . 代码
<!doctype html>
<html>
<head>
<meta charset="utf-8">
<title>图片变换</title>
<style>
.show{width:330px; height:auto; margin:50px auto; background:#eee}
.item{ width:330px; height:auto; float:left; margin:15px;}
p{ padding:15px; color:#ff6600}
.big-photo img{ width:300px; height:400px; border:1px solid #e0e0e0}
.des-small img{ width:30px; height:40px;border:1px solid #e0e0e0; }
.des-small img:hover{ border:1px solid #ff6600}
.clear{clear:both}
</style>
</head>
<body>
<div class="show">
<p>Jquery实现鼠标移动/移过到小图片上时替换掉大图片上的图片</p>
<div class="item">
<a class="big-photo"><img src="http://img4.imgtn.bdimg.com/it/u=1080343512,2178848806&fm=26&gp=0.jpg" tag="big"/></a>
<a class="des-small"><img src="http://img4.imgtn.bdimg.com/it/u=1184104241,3784765089&fm=26&gp=0.jpg" /></a>
<a class="des-small"><img src="http://img0.imgtn.bdimg.com/it/u=2880062395,2491275225&fm=11&gp=0.jpg" /></a>
<a class="des-small"><img src="http://img0.imgtn.bdimg.com/it/u=1624493903,1200566569&fm=11&gp=0.jpg" /></a>
</div>
<div class="clear"></div>
</div>
</body>
</html>
<script src="https://cdn.bootcss.com/jquery/3.4.1/jquery.js"></script>
<script type="text/javascript">
$(function() {
$(".item a").on('mouseenter',function () {
//获取鼠标移动到元素的scr
var temp_small_src = $(this).find('img').attr('src');
//获取大图的元素,然后修改地址为移动元素的src
$(this).siblings('a').find('img[tag=big]').attr('src',temp_small_src);
})
});
</script>