Monday, June 3, 2024
 Popular · Latest · Hot · Upcoming
112
rated 0 times [  118] [ 6]  / answers: 1 / hits: 23472  / 15 Years ago, tue, march 9, 2010, 12:00:00

I have an slider animation but on clX.click event #close div hides before it is animated -250px left. How to wait till the animation completes and then hide #close div?



    $(document).ready(function() {
$(#open).click(function() {
if ($(#close).is(:hidden)) {
$(#open).animate({
marginLeft: -32px
}, 200);

$(#close).show();
$(#close).animate({
marginLeft: 250px
}, 500);
}
});
$(#clX).click(function() {
$(#close).animate({
marginLeft: -250px
}, 500);

$(#open).animate({
marginLeft: 0px
}, 200);

$(#close).hide();
});
});

More From » jquery

 Answers
20

You can add a callback function to the animation. It would be fired once the animation is finished.



$('#clX').click(function() {
$('#close').animate({
marginLeft: -250px
}, 500, function() {
// Animation complete.
$(#close).hide();
//i supose $this.hide() <br/>would work also and it is more efficient.
});
});

[#97389] Friday, March 5, 2010, 15 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
reed

Total Points: 725
Total Questions: 85
Total Answers: 89

Location: Singapore
Member since Sat, Jul 25, 2020
4 Years ago
;