I want to change image when user click on a thumb image, and prevent it to jump to the top of page.
the first code I wrote:
$('#photos-list img').click(function(e) {
e.preventDefault();
var imgObj = new Image();
var targetObj = $('#main_image img');
imgObj.onload = function() {
targetObj.attr('src',this.src);
}
imgObj.src = $(this).attr('rel');
});
the preventDefault() works fine. ok, I want to add some effects to the image changing, like fade in, I add some jquery effects in
$('#photos-list img').click(function(e) {
e.preventDefault();
var imgObj = new Image();
var targetObj = $('#main_image img');
imgObj.onload = function() {
targetObj.hide();
targetObj.attr('src',this.src);
targetObj.fadeIn('normal');
}
imgObj.src = $(this).attr('rel');
});
and this time , the preventDefault does not work, even I gave fadeIn() a preventdefault like:
targetObj.fadeIn('normal', function(e1){e1.preventDefault();});
any methods to solve this problem?