您的位置:首页 > Web前端 > JQuery

Jquery实现鼠标移动/移过到商品小图片上时替换掉大图片上的图片

2017-05-31 20:23 831 查看

Jquery实现鼠标移动/移过到商品小图片上时替换掉大图片上的图片

1 . 效果截图

移动前



鼠标移动到小图上



2 . 代码

<!doctype html>
<html>
<head>
<meta charset="utf-8">
<title>图片变换</title>
</head>
<style type="text/css">
.show{width:330px; height:auto; margin:50px auto; background:#eee}
.item{background:#fff; width:300px; height:auto; float:left; margin:15px;}
p{ padding:15px; color:#ff6600}
.big-photo img{ width:300px; height:300px; border:1px solid #e0e0e0}
.des-small img{ width:30px; height:30px;border:1px solid #e0e0e0; }
.des-small img:hover{ border:1px solid #ff6600}
.clear{clear:both}
</style>
<script src="jquery-1.8.3.min.js"></script>
<script type="text/javascript">
$(function() {
/** 更换小图片 */
$(".item a").hover(function(){
changeImg($(this))
});
});
function changeImg(obj){
if(obj.find("img").attr("alt")=="small"){
var temp_big_src = obj.siblings('a').find('img[alt=big]').attr('src');
var temp_big_url = obj.siblings('a[class=big-photo]').attr('href');
var temp_small_src = obj.find('img').attr('src');
var temp_small_url = obj.attr('href');
obj.siblings('a').find('img[alt=big]').attr('src',temp_small_src);
}
}
</script>
<body>
<div class="show">
<p>Jquery实现鼠标移动/移过到商品小图片上时替换掉大图片上的图片</p>
<div class="item">
<a class="big-photo">
<img src="WR_00001.jpg" alt="big"/>
</a>
<a class="des-small">
<img src="WR_00002.jpg" alt="small"/>
</a>
<a class="des-small">
<img src="WR_00003.jpg" alt="small"/>
</a>
<a class="des-small">
<img src="WR_00004.jpg" alt="small"/>
</a>
</div>
<div class="clear"></div>
</div>
</body>
</html>
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: