med
med

Reputation: 227

moving elements with jquery

How can I use jQuery to move an element from:

position: absolute;
left: 169px;
top: 182px;

to:

position: absolute;
left: 169px;
top: 230px;

with clear moving so not just css, it has to be moving.

Thanks.

Upvotes: 7

Views: 42117

Answers (2)

David Tang
David Tang

Reputation: 93664

What you mean is animation? Assuming an element with id="someElement" already has position:absolute and left:169px, then:

$('#someElement').animate({top: 230});

If you need to set the initial CSS on the element before animating it, then have an extra .css() call before .animate():

$('#someElement').css({
    position: 'absolute',
    left: 169,
    top: 182
}).animate({top: 230});

Upvotes: 9

simshaun
simshaun

Reputation: 21466

http://api.jquery.com/animate/

Demo: http://jsfiddle.net/pHwMK/

JS:

$(function() {
  $("div.ele").animate({ top: '230px' });
});

Upvotes: 11

Related Questions