Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 63657
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 10, 20262026-05-10T18:40:01+00:00 2026-05-10T18:40:01+00:00

So this might be really simple, but I haven’t been able to find any

  • 0

So this might be really simple, but I haven’t been able to find any examples to learn off of yet, so please bear with me. 😉

Here’s basically what I want to do:

<div>Lots of content! Lots of content! Lots of content! ...</div>  ....   $('div').html('Itsy-bitsy bit of content!'); 

I want to smoothly animate between the dimensions of the div with lots of content to the dimensions of the div with very little when the new content is injected.

Thoughts?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. 2026-05-10T18:40:02+00:00Added an answer on May 10, 2026 at 6:40 pm

    Try this jQuery plugin:

    // Animates the dimensional changes resulting from altering element contents // Usage examples:  //    $('#myElement').showHtml('new HTML contents'); //    $('div').showHtml('new HTML contents', 400); //    $('.className').showHtml('new HTML contents', 400,  //                    function() {/* on completion */}); (function($) {    $.fn.showHtml = function(html, speed, callback)    {       return this.each(function()       {          // The element to be modified          var el = $(this);           // Preserve the original values of width and height - they'll need           // to be modified during the animation, but can be restored once          // the animation has completed.          var finish = {width: this.style.width, height: this.style.height};           // The original width and height represented as pixel values.          // These will only be the same as `finish` if this element had its          // dimensions specified explicitly and in pixels. Of course, if that           // was done then this entire routine is pointless, as the dimensions           // won't change when the content is changed.          var cur = {width: el.width()+'px', height: el.height()+'px'};           // Modify the element's contents. Element will resize.          el.html(html);           // Capture the final dimensions of the element           // (with initial style settings still in effect)          var next = {width: el.width()+'px', height: el.height()+'px'};           el .css(cur) // restore initial dimensions             .animate(next, speed, function()  // animate to final dimensions             {                el.css(finish); // restore initial style settings                if ( $.isFunction(callback) ) callback();             });       });    };   })(jQuery); 

    Commenter RonLugge points out that this can cause problems if you call it twice on the same element(s), where the first animation hasn’t finished before the second begins. This is because the second animation will take the current (mid-animation) sizes as the desired ‘ending’ values, and proceed to fix them as the final values (effectively stopping the animation in its tracks rather than animating toward the ‘natural’ size)…

    The easiest way to resolve this is to call stop() before calling showHtml(), and passing true for the second (jumpToEnd) parameter:

    $(selector).showHtml('new HTML contents')            .stop(true, true)            .showHtml('even newer contents'); 

    This will cause the first animation to complete immediately (if it is still running), before beginning a new one.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

this might be really simple and I've tried searching but I haven't been able
There might be a really simple answer for this but I've been pondering it
This might be a really simple thing but i was unable to find an
This might have been asked before but I'm really looking for a simple way
I feel like this might be really simple but I'm just not getting it
There might be a really simple solution to this question, but i just don't
This is probably a really simple one but I couldn't find the answer. I
This might be a pretty simple question, but if there really is a difference,
This might be really simple, but i cannot figure out the problem with this
I know this question might be repeated many times but would really appreciate any

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.