开发者

How do I reset the values in javascript without using .animate, related with jquery

I'm changing this div's (#logo)attributes like this

$('#logo').stop().animate({
left: 150,
开发者_如何学Goheight: 78,
marginTop: 45
}

After 2 seconds after animation is finished, I make it disappear with .hide('slow'), now while it is hidden I wan't to change it's attributes the same left, height and marginTop to old default ones without animation, because when I do through animate it appears. I mean becomes display:block. I want to make this hidden and then fideIn.


You can use .css in a callback which runs once the animation is complete:

$('#logo').stop().animate({
    left: 150,
    height: 78,
    marginTop: 45
}, function() {
    $(this).css({
        left: 150, //Change these to whatever they were before the call to animate
        height: 78, 
        marginTop: 45
    }).fadeIn();
});


Just use the jQuery css function to set the properties back to their original values.

$('#logo').stop().animate({
    left: 150,
    height: 78,
    marginTop: 45
}).hide('slow', function() {
    $(this).css({
      left: 0,
      height: 50,
      marginTop: 10
    }).fadeIn(); 
}); 

JSFiddle Example

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜