2Noob2Good
2Noob2Good

Reputation: 157

Simple animation div to div with javascript

Is it possible to move a div to another div only using javascript?

I am very bad at javascript/jquery and I just wanted to do a simple animation of products to move into a shopping cart.

If it is not possible (or very hard) to do with javascript only I am also willing to do it with jquery.

I also wanted to eventually add an effect of fade out + shrink.

Upvotes: 0

Views: 112

Answers (3)

Austin
Austin

Reputation: 1

<script type="text/javascript">
div1.onclick = function()
{
div1.style.left = "12px" //or somewhere within div2
div1.style.top = "12px" //or somewhere within div2
}
</script>

Upvotes: 0

Damien Black
Damien Black

Reputation: 5647

assuming the div1 is absolutely positioned, you could do something like this:

var new_position = $(".div2").offset();
$(".div1").animate(new_position, 5000); // where 5000 is time in mil

fading out and shrinking can be done using the animate property as well

Upvotes: 1

Joseph
Joseph

Reputation: 119827

Is it possible to move a div to another div only using javascript?

Yes

I am very bad at javascript/jquery and I just wanted to do a simple animation of products to move into a shopping cart.

If it is not possible (or very hard) to do with javascript only I am also willing to do it with jquery.

Here's MDN for JS docs, and jQuery's docs. You can start off from there

I also wanted to eventually add an effect of fade out + shrink.

You can play around with jQueryUI for effects, especially .hide()

Upvotes: 0

Related Questions