Go Back   CodingForums.com > :: Client side development > JavaScript programming > JavaScript frameworks

Before you post, read our: Rules & Posting Guidelines

Reply
 
Thread Tools Rate Thread
Enjoy an ad free experience by logging in. Not a member yet? Register.
Old 10-24-2008, 05:22 PM   PM User | #1
Spudhead
Senior Coder

 
Spudhead's Avatar
 
Join Date: Jun 2002
Location: London, UK
Posts: 1,856
Thanks: 8
Thanked 110 Times in 109 Posts
Spudhead is on a distinguished road
jQuery - animated image swap

I'm trying to animate a simple image swap but it's not quite working right. Details below, here's my code thus far:

Code:
	$('#zoom_control a').click(function(){
		var oImg = $('.current_page').find('img');
		oImg.animate({opacity: 0}, 1000, '',function(){
			var sOldSrc = oImg.attr('src');
			if (sOldSrc.indexOf("_zoom.png") > 0){
				sNewSrc = sOldSrc.replace("_zoom.png", ".png");
				$(this).html('Zoom out');
			}else{
				sNewSrc = sOldSrc.replace(".png", "_zoom.png");
				$(this).html('Zoom in');
			}
			oImg.attr('src', sNewSrc);
			oImg.animate({opacity: 1}, 1000);
		});
		return false;
	});

So: find the image to be swapped, and animate its opacity down to 0. When the animation finishes, use the callback function to swap the src and animate the opacity back up to 1.

Simple enough, and I was surprised not to find an existing plugin that does exactly that. If you know of one, you could probably save us both some trouble

In any case, the problem with this one is that the image src swap seems to screw with the opacity. It's difficult to tell what it's doing exactly, but the image fades out ok, but then flashes back up briefly, then switches immediately to the new image.

Any ideas?
Spudhead is offline   Reply With Quote
Old 10-31-2008, 07:13 PM   PM User | #2
Spudhead
Senior Coder

 
Spudhead's Avatar
 
Join Date: Jun 2002
Location: London, UK
Posts: 1,856
Thanks: 8
Thanked 110 Times in 109 Posts
Spudhead is on a distinguished road
Well, I sort of fixed it in the end.. by animating the opacity of the container div instead of the image itself.
Spudhead is offline   Reply With Quote
Old 04-14-2009, 04:09 PM   PM User | #3
Uzbekjon
New Coder

 
Join Date: Feb 2009
Location: Uzbekistan
Posts: 17
Thanks: 0
Thanked 0 Times in 0 Posts
Uzbekjon is an unknown quantity at this point
I came across this thread while searching for "jquery image swap".

Thought I would share with you the article I found on jquery image swap, since I already have an account here :)
Uzbekjon is offline   Reply With Quote
Reply

Bookmarks

Jump To Top of Thread


Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT +1. The time now is 09:22 AM.


Advertisement
Log in to turn off these ads.