lastNerve
lastNerve

Reputation: 121

animate offset().left

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.

Upvotes: 2

Views: 15258

Answers (4)

Starx
Starx

Reputation: 78971

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

Upvotes: 3

codewrangler
codewrangler

Reputation: 350

Use the animate function of jQuery to do so.

$('button').mouseover(function () {
    $('#mydiv').animate({left: '100px'}, 'slow'); 
});

http://jsfiddle.net/HPpEY/

Upvotes: 1

gopi1410
gopi1410

Reputation: 6625

Yeah correct javascript solutions have already been provided in the answers. You could also consider using css3 transitions. Check out a jsFiddle I wrote just now.

Upvotes: 0

Loktar
Loktar

Reputation: 35309

Does the styling of your element give it the ability move to the left? The following works for me just fine.

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

Live Demo

Like the comment above, show us what you are using :).

Upvotes: 4

Related Questions