JSFiddle - React, Tailwind, and code Playground

by maccman

HTML

<div class="element"></div>

CSS

body { margin: 20px; }
.element {
    width: 100px;
    height: 100px;
    background: red;
}

JavaScript

var defaults = {
  duration: 400,
  easing: ''
};

$.fn.emulateTransitionEnd = function(duration) {
  var called = false, $el = this;
  $(this).one('webkitTransitionEnd', function() { called = true; });
  var callback = function() { if (!called) $($el).trigger('webkitTransitionEnd'); };
  setTimeout(callback, duration);
};

$.fn.redraw = function(){
   return $(this).each(function(){
     var redraw = this.offsetHeight;
   });
};

$.fn.transition = function (properties, options) {
  var $el = $(this);
  options = $.extend({}, defaults, options);
  properties['webkitTransition'] = 'all ' + options.duration + 'ms ' + options.easing;
  
  var callback = function(){
    $el.dequeue();
    if (options.complete) options.complete.apply($el);
  };
    
  $el.queue(function(){
    $el.one('webkitTransitionEnd', callback);
    $el.emulateTransitionEnd();
    $el.css(properties);
  });
      
  return this;
};

  $('.element')
      .css({marginTop: 100})
      .redraw()
      .transition({marginTop: 200});