[Webinar] Streamline your web hosting managementRegister Today

x
?
Solved

move div to a div with animation

Posted on 2010-04-05
6
Medium Priority
?
721 Views
Last Modified: 2012-05-09
<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?
0
Comment
Question by:johndenny
6 Comments
 
LVL 2

Expert Comment

by:Manikandanr
ID: 29873161
hi johndenny,

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

Hope it helps....


moving-divs.zip
0
 

Author Comment

by:johndenny
ID: 29875757
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
 
LVL 19

Accepted Solution

by:
Albert Van Halen earned 1000 total points
ID: 29896521
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
[Webinar] Improve your customer journey

A positive customer journey is important in attracting and retaining business. To improve this experience, you can use Google Maps APIs to increase checkout conversions, boost user engagement, and optimize order fulfillment. Learn how in this webinar presented by Dito.

 
LVL 2

Expert Comment

by:Manikandanr
ID: 29988554
hi johndenny:
                   Try this link.........
                        http://jstween.blogspot.com/
and also look at my sample  attached........
chainable-effects.html
0
 
LVL 10

Assisted Solution

by:Terry_focus
Terry_focus earned 1000 total points
ID: 30008676
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

Featured Post

Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Hi all! Recently there was EE question and the person wanted to have a multi-column textbox <div> selection, so as a first step to answer I provided a link but that was not complete with JavaScript selection, but had a good style sheet. So as a ques…
Requirements JQuery 1.6+ HTML CSS Introduction This article was inspired by an EE question (http://www.experts-exchange.com/Programming/Languages/Scripting/JavaScript/Q_28372511.html) on how to make a page show some balloons animate up a page…
The viewer will learn how to dynamically set the form action using jQuery.
The viewer will learn the basics of jQuery including how to code hide show and toggles. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery…
Suggested Courses
Course of the Month8 days, 7 hours left to enroll

608 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question