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 6870473
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T03:41:17+00:00 2026-05-27T03:41:17+00:00

I have setup a div with an original height at auto and a width

  • 0

I have setup a div with an original height at auto and a width at a percentage (48%).

I’ve allowed the div to be expanded on a user click. The div will expand to the height of 80% (from auto) and the width of 100% (from 48%). The expand is animated (.animate)

Here’s the code, for the expanding:

var e_p="in"; // The default of the div is in.

$(".my_expand_button").click(function() { 

if (e_p == 'in'){
//the percentages i want the div to expand to...

var p_h= 0.8; 
var p_w= 1.0;

$(".box1").css("opacity","0");// i make the the other divs invisible

$('.box2').animate({

height:($(".wrapper").height()* p_h), // expand height

width:($(".wrapper").width()* p_w)},'fast'); //expand width

e_p = 'out'; //the div has just been expanded, so it will go back to normal size on the second user click.
}

Now the above works fine. It all expands like it’s supposed to.

Here is the problem code to take it back to normal size (on the second user click);

else if (e_p == 'out'){ 
var p_w= 0.48;

    $(".box1").css("opacity","100");// make the the other divs visible

    $('.box2').animate({

    height:200, // make height 200px for the moment

    width:($(".wrapper").width()* p_w)},'fast'); //take the width back to its normal percentage
$(".box2").css("height","auto");//change the height back to auto....

    e_p = 'in'; //the div has just been squashed, so it will expand again on the third user click.
    }

Now the div goes back to 200px and the width looks like it goes back to 48% but when i zoom out of the page, the width should expand (to fill 48% percent of the page) but it doesn’t.

And the height does not go back to auto as it does not expand with the content (text). The text just goes over the div and on the wrapper (as if an absolute position is set).

  • 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. Editorial Team
    Editorial Team
    2026-05-27T03:41:18+00:00Added an answer on May 27, 2026 at 3:41 am

    The problem is that you set the height to “auto” WHILE the animation is running.

    You need to set the height to auto AFTER the animation completed (using a callback).

    About the width, the problem is that when you set the width with the width() method, jQuery is setting the width to the absolute value that was computed at that time (instead of the explicit 48% value). To solve just make an explicit call to the css with 48% after the animation finished.
    Here is what you need for both problems:

    $('.box2').animate({
        height:200, // make height 200px for the moment
        width:($(".wrapper").width()* p_w)},'fast', function() {
          $(".box2").css({height : "auto", width : '48%'});
    });
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a setup like this: <div id=container> <div id=close>Close</div> </div> Then in my
On my portfolio page I have this setup: <div id=portfolio> <ul id=sites> <li> <h3><a
I have a HTML document with the below setup: <div class=main-div style=padding: 5px; border:
I've been battling to get this right...basically I have the following HTML setup: <div
I have the following title div setup, but when only the leftmost div has
I have the following setup on 2 div tags: <div id='div1' style='position: absolute; z-index:
I have a setup like this: <div class=item> <img src=.../> <span class=item-detail></span> <span class=item-detail></span>
I have a setup lets say like follows: <div id=nav> <div id=innernav> //With dynamic
I have setup a div that is resizable: $(mydiv).resizable(); Now when you go to
I have a setup that requires a header div and a footer div to

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.