Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

jQuery animate help

Tags:

jquery

This isn't working. I'm trying to replicate the animate to red and then remove effect as in the WordPress admin. The element gets removed, but it doesn't animate before that.

$('.delete-item').live('click', function(){
            $(this).parent().parent().animate({backgroundColor: '#ff0000'}, 'slow').empty().remove();
        });
like image 591
JorgeV44 Avatar asked Apr 17 '26 10:04

JorgeV44


2 Answers

As for as i know you can not animate the background color, you need the color plugin in order to do that.

like image 192
Sarfraz Avatar answered Apr 20 '26 06:04

Sarfraz


Use the .animate() callback, like this:

$('.delete-item').live('click', function(){
  $(this).parent().parent().animate({backgroundColor: '#ff0000'}, 'slow', function() {
    $(this).empty().remove();
  });
});

The callback won't execute until the animation is complete, your current method queues the animation but only executes one frame of it before the element is removed from the DOM, this lets the entire animation execute then remove it.

like image 26
Nick Craver Avatar answered Apr 20 '26 07:04

Nick Craver



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!