April 26, 2012

animate offset().left

Question by fuey

I’ve been all over the place looking for this. There are some answers out there but none of them work.

All I want to do is slowly move a div to the left when a user does a mouseover on a button.

This works to make the div move:

$("#myDiv").offset({left:-1000});

but all my attempts to animate the move cause the move itself to fail.

Answer by Starx

Use .animate() function like this

$("#myDiv").animate({ left: '-1000' });

Update:
Since your division is floated to the left, you can animate the property using marginLeft instead.

$("#myDiv").animate({ marginLeft: '-1000' });

Demo

Author: Nabin Nepal (Starx)

Hello, I am Nabin Nepal and you can call me Starx. This is my blog where write about my life and my involvements. I am a Software Developer, A Cyclist and a Realist. I hope you will find my blog interesting. Follow me on Google+

...

Please fill the form - I will response as fast as I can!