我有一个页面,上面有一张带有许多缩略图的大图片。当您将鼠标悬停在缩略图上时,主图像将变为您刚刚将鼠标滑过的图像。问题是我拥有的缩略图越多,重复的代码就越多。我怎么能减少它?
Jquery 代码如下。
<script type="text/javascript">
$('#thumb1')
.mouseover(function(){
$('#big_img').fadeOut('slow', function(){
$('#big_img').attr('src', '0001.jpg');
$('#big_img').fadeIn('slow');
});
});
$('#thumb2')
.mouseover(function(){
$('#big_img').fadeOut('slow', function(){
$('#big_img').attr('src', 'p_0002.jpg');
$('#big_img').fadeIn('slow');
});
});
$('#thumb3')
.mouseover(function(){
$('#big_img').fadeOut('slow', function(){
$('#big_img').attr('src', '_img/p_0003.jpg');
$('#big_img').fadeIn('slow');
});
});
$('#thumb4')
.mouseover(function(){
$('#big_img').fadeOut('slow', function(){
$('#big_img').attr('src', '0004.jpg');
$('#big_img').fadeIn('slow');
});
});
</script>
#big_img
= 全尺寸图像的 ID
#thumb1
, #thumb2
, #thumb3
, #thumb4
= 缩略图的 ID
如果有帮助,该页面的主要代码是 PHP。