user3421904
user3421904

Reputation:

animate not working-JQuery

Am I doing anything wrong that my simple animate does not work?

fiddle

$('#my_btn').click(function(){
    alert('clicked');
  $("#my_txt").animate({left:'350px'});
});

Thanks

Upvotes: 0

Views: 33

Answers (2)

Alessandro Minoccheri
Alessandro Minoccheri

Reputation: 35973

left is for element in position absolute. you can use marginLeft like this:

$('#my_btn').click(function(){
    alert('clicked');
  $("#my_txt").animate({marginLeft:'350px'});
});

DEMO

or set position:absolute to your span like this to use left in animate:

CSS

#my_txt{
    position:absolute;
}

jQuery

$('#my_btn').click(function(){
    alert('clicked');
  $("#my_txt").animate({left:'350px'});
});

Upvotes: 0

adeneo
adeneo

Reputation: 318342

An element must have a position other than the default static for top and left to have any effect

#my_txt {position: relative; }

FIDDLE

Preferably it would have an initial left style set as well

#my_txt {
    position: relative; 
    left : 0;
}

Upvotes: 1

Related Questions