I want to change a text inside a div after it disappears and then show div again. The problem is that 'complete' callback fires not when the first animation completes.
var $cart = $('.cart');
$cart.animate(
{
opacity: 0
},
{
complete: function(){
console.log($cart.css('opacity'));
setTimeout(function(){
console.log($cart.css('opacity'));
}, 100);
setTimeout(function(){
console.log($cart.css('opacity'));
}, 200);
}
}
)
The output is:
1
0.082741
1.83913e-09
Full code, which doesn't work properly:
<a class="cart " data-tooltip="tt_cart" href="/cart">
<svg class="ico">
<use xmlns:xlink="http://www.w3.org/1999/xlink" xlink:href="/assets/site-skin/icons.svg#ico-shopping-basket"></use>
</svg>
<span class="amount_in_cart">0</span>
</a>
function increase_amount_in_cart(){
var $amount_in_cart = $('.amount_in_cart');
var amount_in_cart = parseInt($amount_in_cart.text());
var $cart = $('.cart');
$cart.animate(
{
opacity: 0
},
{
complete: function(){
$amount_in_cart.text(amount_in_cart + 1);
$cart.animate({opacity: 1}, 'fast');
},
duration: 'fast'
}
)
}
jQuery version is 1.11.2.