move div to a div with animation

<div id="test1">test 1</div>
<div id="test 2">test 2</div>

how to move test1 to test2 with animation, and test2 will be slowly go away in jquery?
johndennyAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

ManikandanrCommented:
hi johndenny,

Try with file that i attached below........

Hope it helps....


moving-divs.zip
0
johndennyAuthor Commented:
thanks mani, but that's a huge plugin, i just want to write my simple one, using animate .
And i just want to move test 1 to test2 div with a little animation.
0
Albert Van HalenAnalyst developerCommented:
You have to position the divs absolute at first.
Then use this code
$(function() {
	// Bind click event on document ready
	$("#test1").bind("click", function() {
		var o = $("#test2").offset();
		$("#test1").animate({
			"left": o.left,
			"top": o.top
		}, "slow");
		$("#test2").fadeTo("slow", 0);
	});
});

Open in new window

0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
Cloud Class® Course: MCSA MCSE Windows Server 2012

This course teaches how to install and configure Windows Server 2012 R2.  It is the first step on your path to becoming a Microsoft Certified Solutions Expert (MCSE).

Dhanasekaran SengodanCommented:
0
ManikandanrCommented:
hi johndenny:
                   Try this link.........
                        http://jstween.blogspot.com/
and also look at my sample  attached........
chainable-effects.html
0
Terry_focusCommented:
Try something like this
$(function(){
	//Cache selector for div1 and div2
	var $div1 = $("#div1");
	var $div2 = $("#div2");
	//Get the position of div1
	var pos1 = $div1.offset();
	//Get the position of div2
	var pos2 = $div2.offset();
	//animate div 1 to the position of div 2
	
	//Using div 1
	$div1
	//Move to absolute positioning so we can move, but make sure it stay in the same place
	.css({
		position:"absolute",
		left:pos1.left,
		top:pos1.top
	})
	//Start animation
	.animate({
		left:pos2.left,
		top:pos2.top
	},500,function(){
		//Now animation is finished, fade out div 2
		$div2.fadeOut(500)
	});	
});

Open in new window

0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
jQuery

From novice to tech pro — start learning today.