You should always try using CSS3 transitions instead of jQuery animations. Here I use the CSS3 transition to fade out the .square , and then I wait until the transition completes to set the display to none .
If you animate an element in jQuery, for example using fadeOut , you will see what happens. It basically sets the opacity to 1, and then adjusts this value to zero with minimal increments. It is very inefficient. Therefore, it is best to always use CSS3 transitions and animations where possible.
Attenuation: https://jsfiddle.net/danhaswings/znLL0ws5/1/
Attenuation: https://jsfiddle.net/danhaswings/kjgmxa8x/
HTML
<div class="square"></div>
CSS
.square { width: 100px; height: 100px; background-color: red; transition: opacity 1s ease-in-out; }
JQuery
var $square = $('.square'); $square.css('opacity', '0'); $square.one("webkitTransitionEnd otransitionend oTransitionEnd msTransitionEnd transitionend", function() { $(this).css('display', 'none'); });
source share