我有一个关于一些JavaScript的问题,有一个大图片和缩略图,我的JavaScript函数改变了从缩略图中获取的大图片的链接,它工作得很好,但我还有一个高幻灯片,它适用于大图片,当大图片被点击时,它的实际大小显示在高幻灯片中,但我有一个小问题,当我改变大图片的链接时,它会自动出现这个图片的两个链接,一个在大图片中,另一个在缩略图中,所以我需要在点击后删除缩略图中的另一个链接。所以这就是我现在的脚本:
$(document).ready(function() {
$('.image').click(function(event) {
event.preventDefault();
var imagePath = $(this).attr("href");
var newImg = new Image;
newImg.onload = function(){
$('#big_picture2').hide();
$('#big_picture2').attr('src', imagePath);
$('.product_image_large').attr('href', imagePath);
$('#big_picture2').fadeIn('slow');
};
newImg.src = imagePath;
});
});发布于 2011-05-30 17:23:01
未经测试,但我认为这应该是可行的:
$(document).ready(function() {
$('.image').click(function(event) {
event.preventDefault();
//add big picture link to active thumbnail
$('.image.active').attr('href',$('#big_picture2').attr('src')).removeClass('active');
//set new active thumbnail
$(this).addClass('.active');
var imagePath = $(this).attr("href");
//remove this href
$(this).removeAttr('href');
var newImg = new Image;
newImg.onload = function(){
$('#big_picture2').hide();
$('#big_picture2').attr('src', imagePath);
$('.product_image_large').attr('href', imagePath);
$('#big_picture2').fadeIn('slow');
};
newImg.src = imagePath;
});
});https://stackoverflow.com/questions/6173761
复制相似问题