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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T04:32:57+00:00 2026-05-23T04:32:57+00:00

I have two divs stacked one above the other, with my code expanding the

  • 0

I have two divs stacked one above the other, with my code expanding the boxes when your mouse hovers on a div. When you remove your mouse from the div, the div shrinks back to the original size.

My code works just fine and dandy when you swipe the mouse into a div and then out of a div into the blank area of the page. However, if you try moving the mouse between the two divs, everything goes haywire, and now the correct boxes no longer shrink and the overall functionality is lost.

Here is my code:

$(".divbox1").hover(function() {    
var height = $(this).height();
var height2 = $(this)[0].scrollHeight;

if (height2 > 35) {

    //Current position in relation to the page
    var offsetTop = $(this).offset().top;
    var offsetLeft = $(this).offset().left;

    //Clone the code and attach it to the page
    $(this).clone().css({
        position: "absolute",
        top: offsetTop,
        left: offsetLeft
    }).attr("id", "cloned").appendTo("body");

    //Hide the code underneath
    //$(this).css("visibility", "hidden");

    $('#cloned').animate({
        height: height2
    }, 150).bind('mouseleave', function() {
        var cloned = $(this);
        //Animate back and remove
       cloned.animate({
            height: height
        }, 300, function() {
            cloned.remove();
            //Show the code underneath
            //$(this).css("visibility", "visible");
        });


    });
}
 });

And this my associated HTML and CSS

    .divbox1 {
color: #100;
background-color: #f9f9f9;
border: 1px solid silver;
overflow: hidden;
width: 200px;
height:35px;
}

    <div class="divbox1" id="one">
sdsdsadasdsad<br />
sadasdsdaasdadsadssdsdsadasasdasdsdsddsasdasdasdasdasddasadsasd<br>
dasdasasdasdsad
<br /><br />
Really Tall box!
    </div>
   <br />
    <div class="divbox1" id="two">
  Second box<br />
yada ydad<br />
yada yada<br />
yada yada<br />
    </div>

For those interested, the project is also on Jsfiddle: http://jsfiddle.net/hQkFH/10/

Also incase anyone was wondering why I cloned the box before animating, its because I wnt the open box to overwrite anything on the page underneath it (in the case of the top box, the second box)

Thank you!

  • 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-23T04:32:58+00:00Added an answer on May 23, 2026 at 4:32 am

    Have you tried adding $('#cloned').remove(); before cloning the divbox?

    I think the problem is that you end up with two divs with id=”cloned” when you enter in both hover events

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

Sidebar

Related Questions

We have two DIVs, one embedded in the other. If the outer DIV is
I have two divs, one within the other. The outer div (the container) is
I have two divs both containing images. Here is some example code: <div id=one>
I have two divs one above the other. The second on is absolutely positioned
I have two divs that are right above each other. The bottom one has
i have two divs one floated to the left and the other to the
I have a div with two nested divs inside, the (float:left) one is the
I have two divs, one that holds some stuff and the other with all
I have two divs: one draggable and one droppable <div id=draggable class=block runat=server> </div>
I have two divs, one nested inside of the other. The parent element has

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.