Skip to content

Instantly share code, notes, and snippets.

@cecilemuller
Created November 10, 2012 04:42
Show Gist options
  • Save cecilemuller/4049939 to your computer and use it in GitHub Desktop.
Save cecilemuller/4049939 to your computer and use it in GitHub Desktop.
jQuery: replace HTML contents with a smooth height animation
(function($){
$.fn.replace_html = function(html){
return this.each(function(){
var el = $(this);
el.stop(true, true, false);
var finish = {width: this.style.width, height: this.style.height};
var cur = {width: el.width() + "px", height: el.height() + "px"};
el.html(html);
var next = {width: el.width() + "px", height: el.height() + "px"};
el.css(cur).animate(next, 300, function(){el.css(finish);});
});
};
})(jQuery);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment