JimmyBanks JimmyBanks - 14 days ago 5
CSS Question

jQuery animate movement left and right

Using jquery's

.css()
i am changing the left attributes value to move a div left or right. Im looking for a way to animate this change as it occurs. Nothing ive tried is working, ive tried jQueryUI's
.show(slide)
function, but this moves the whole div, rather than just the 120px movement i need.

This is my current function which is working without an animation:

$('#plrt').live("click",function(){
var lm=$('.plwid').css("left");
lm = (parseInt(lm) + 120);
$('.plwid').css("left", lm);
});


this is the slide function, it does not work properly as the whole div goes from
display:hide
to
display:show
, rather than just moving the pixel change

Answer

try animate()

$('#plrt').on("click",function(){
    $('.plwid').animate({ left: '+=120' }, 400 );
});
Comments