Is there a way to prevent my cell from resizing during the initiation of a jQuery animate effect?

After coding a 2x2 DIV table, I encountered an issue where the left side of the cell appears when hovering over the right cell. However, the left cell is hidden when the mouse leaves the right cell, utilizing a jQuery animate effect.

I'm facing a problem with my right cell having a bounce effect or resizing whenever the animation starts. Can anyone provide advice on how to prevent this resizing?

$(document).ready(function () {

  $('#top, #bottom')
  .mouseover(function () {
    $('.divTableCell1').stop(true, false).animate({
      width: "300px",
      opacity: "1"
    });
  })
  .mouseleave(function () {
    $('.divTableCell1').stop(true, false).animate({
      width: "100px",
      opacity: "0"
    });
  });
  
});
.divTable {
  display: table;
  float: right;
}
.divTableRow {
  display: table-row;
}
.divTableHeading {
  background-color: #EEE;
  display: table-header-group;
}
.divTableCell1, .divTableHead, .divTableCell2 {
  /*border: 1px solid #999999;*/
  display: table-cell;
  padding: 3px 10px;
}
.divTableHeading {
  background-color: #EEE;
  display: table-header-group;
  font-weight: bold;
}
.divTableFoot {
  background-color: #EEE;
  display: table-footer-group;
  font-weight: bold;
}
.divTableBody {
  display: table-row-group;
}
.divTableCell1 {
  vertical-align: middle;
  opacity: 0;
  background-color: red;
}
.divTableCell2 {
  width: 30px;
  background-color: dodgerblue;
}

.divTableCell2 img {
  width: 30px;
  height: 30px;
  display: block;
  margin-left: auto;
  margin-right: auto;
}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.min.js"></script>
<div class="divTable">
  <div class="divTableBody">

    <div class="divTableRow">
      <div class="divTableCell1">This is Menu 1</div>

      <div id="top" class="divTableCell2">
        <img src="img/alert.png" />
      </div>
    </div>

    <div class="divTableRow">
      <div class="divTableCell1">This is Menu 2</div>

      <div id="bottom" class="divTableCell2">
        <img src="img/setting.png" />
      </div>
    </div>

  </div>
</div>

Thanks

Answer №1

To prevent the left border of the right element from bouncing, you should apply the CSS property overflow: hidden;.

$(document).ready(function () {

  $('#top, #bottom')
  .mouseover(function () {
    $('.divTableCell1').stop(true, false).animate({
      width: "300px",
      opacity: "1"
    });
  })
  .mouseleave(function () {
    $('.divTableCell1').stop(true, false).animate({
      width: "100px",
      opacity: "0"
    });
  });
  
});
body 
{
margin: 0; 
padding: 0; 
font-size: 100%; 
font-family: Arial, Helvetica, sans-serif;
}
.divTable {
margin-top: 100px;
}
.divTableRow {
margin: 0;
padding: 0;
    height: 55px;
}
.divTable {
width: 100%;
text-align: right;

}
.divTableCell2 img {
height: 55px;
width: 70px;
    padding: 5px 10px;
}
.in_l {
display: inline-block;

}
.divTableCell2 {
background-color: dodgerblue;
cursor: pointer;
overflow: hidden;

}
.divTableCell1 {
width: 100px;
    height: 55px;
    background: red;
    margin: 0 -4px 0 0;
   line-height: 6rem;
       padding-left: 10px;
text-align: left;
overflow: hidden;
opacity:0;
}
<link href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/css/bootstrap.min.css" rel="stylesheet" integrity="sha384-1q8mTJOASx8j1Au+a5WDVnPi2lkFfwwEAa8hDDdjZlpLegxhjVME1fgjWPGmkzs7" crossorigin="anonymous">
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>

<div class="divTable">
  <div class="divTableBody">

<div class="divTableRow">
  <div class="divTableCell1 in_l">This is Menu 1</div>

  <div id="top" class="divTableCell2 in_l">
<img src="http://i.imgur.com/ILEhfiz.png" />
  </div>
</div>

<div class="divTableRow">
  <div class="divTableCell1 in_l">This is Menu 2</div>

  <div id="bottom" class="divTableCell2 in_l">
<img src="http://i.imgur.com/8IQhev1.png" />
  </div>
</div>

  </div>
</div>

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

VueJS component fails to remain anchored at the bottom of the page while scrolling

I am currently using a <md-progress-bar> component in my VueJS application, and I am trying to make it stay fixed at the bottom of the screen when I scroll. I have attempted to use the styles position: fixed;, absolute, and relative, but none of them ...

How can I fetch a value from a database and set it as the selected option in a

I am facing an issue with the usage of the selectpicker plugin from Bootstrap in order to select multiple items. My requirement is to create a modal for editing where the data is fetched from previous records, particularly an array. I am looking for a way ...

Validating Tabs with jQuery

After creating a page with jQuery tabs, my next step is to implement validation using the jQuery Validation plugin. However, I have encountered an issue where only the selected tab is being validated when I submit the form. The inactive tabs are not getti ...

Displaying group field data in one page on JQGrid when pagination is enabled

Is there a way in JQGrid to display group data on one page? Specifically, if displaying all items from an order would exceed the list limit, I want to only show data up to the previous order without exceeding the limit. How can this be achieved? ...

Retrieve duplicate data from the database by utilizing jQuery AJAX on mouse movement

I retrieved data from a database and it is stored in display.php. However, when using mousemove to view the data, it keeps repeating every time I hover over it. Here is the code for the mouse move function: $(line.node).mousemove(get_over_handler(country ...

The Unexpected Mishaps of CSS Grid Layout

I attempted to create a grid using CSS, but I seem to have made an error somewhere in my code. Can someone please take a look at my jsFiddle link and provide some guidance? jsFiddle /*Grid*/ .container { width: 100%; max-width: 1200px; } .row:before, ...

How can we improve our vertical division method?

Looking for a more efficient way to create a vertical divider between two divs. I want the divider to be centered between the "why choose" and "gallery" sections. Here is an example of what I'm trying to achieve. I've attempted the following co ...

Vertically center text in an email within a div using HTML

i'm struggling to perfectly center the text within a div in an HTML email. While it appears fine in Browserview with proper line-height, issues arise in Apple Mail and Outlook where it doesn't align vertically. <div style='width: 80%; ...

When using the jQuery datepicker with the minDate set to 0, any past dates entered in the text box will be automatically reset to the current date

How can I prevent users from selecting past dates in a jQuery datepicker, while keeping any existing past dates displayed as is? My current code looks like this: $("#t1").datepicker({ minDate:0 }); And the text box code is, <input type="t1" va ...

Sending a variety of data values via the AJAX data parameter

I have successfully passed data from a form using a standard AJAX call. Now, my goal is to include two additional variables called elat and elng in this process. What would be the most effective way to incorporate the values of filter.serialize(), elat, a ...

Using jQuery to open a file containing an umlaut in its filename

I am trying to retrieve the content from a file that contains an umlaut in its filename using a jquery load request. I understand that it is not recommended to use umlauts in filenames. What's puzzling is that I have used the same code, with the same ...

The back button fails to refresh the page on a website utilizing Ajax technology

Recently, I implemented AJAX on a client's website to introduce some smooth animations for page transitions. When navigating from the homepage of firedogcreative.com to the edit page, and then to one of the work pages, we see a history like this: fir ...

Navigation menu with submenus containing buttons

I attempted to incorporate a dropdown into my existing navigation bar, but unfortunately, the dropdown content disappeared after adding the necessary code. I am now at a loss on how to troubleshoot this issue and make the dropdown function properly. Despit ...

Move your cursor over a specific element to change the div located before it, rather than the one after

Is it possible to have <div> B affect <div> A on hover, instead of the other way around? I've only seen code for the reverse using (+) in CSS. #b:hover + #a { background: #ccc } <div id="a">Div A</div> <div id="b"> ...

Discover the hexadecimal color code generated from an rgba color

Do you know of a service that can determine the final hexadecimal value of an rgba color? For instance, if my body background-color is set to #FF0000 and my header is positioned over it with a background-color of rgba(0,0,0,.7), how can I find out what the ...

What is the best way to adjust the size of an image using CSS, especially with flexbox

I'm attempting to arrange 3 images in a row using flexbox. I also need to adjust the size of the first image because it is too large. However, my CSS styles are not being applied correctly. Each image is enclosed in its own div with a class of flex-it ...

Utilize jQuery to conceal the submit button of a form while maintaining its functionality

Is there a way to conceal the form submit button while still maintaining its ability to function when pressing Return/Enter? The use of .hide() (or display:none with CSS) eliminates the submit on return functionality. ...

Creating a responsive grid division

.subcategory-main-wrapper { display: grid; grid-template-columns: repeat(4, max-content); position: absolute; width: 100%; column-gap: 4%; justify-content: center; height: 360px; @media @tabletScreens { height: 280px; } @media @ ...

show a picture and text side by side

Here's the CSS code I'm using: <style type="text/css"> #box { width:100%; height:80px; background-color:#eeeeee; } .box-inner { width:80%; margin:0 auto 0 auto; text-align:center; } #text, #text a { font-siz ...

Create a JavaScript and jQuery script that will conceal specific div elements when a user clicks on them

Within my navigation div, there exists another div called login. Through the use of JavaScript, I have implemented a functionality that reveals additional divs such as login_name_field, login_pw_field, register_btn, do_login_btn, and hide_login upon clicki ...