jQuery animate width without reflow of content?

608 Views Asked by At

I've searched here and googled for hours, but have yet to find a solution to this problem... Basically, I have a giant list of icons that once each list item is hovered, it expands to reveal the textual name of the item. However, upon animating the width, the entire document is forced to reflow.

Is there any way around this? I've tried every combination of jQuery and css I can think of to no avail. I've attempted adding absolute positioning (relative to the parent UL) once hovered with positions based on jQuery position()... However, that doesn't work as I had hoped.

I'd really like to be able to hover each icon, have it expand to show the text, but rather than reflowing the rest of the content, simply act as if it is in a fixed position and therefor not interacting with the rest of the content layout.

Here's the animation bit:

  $('.service-generator li').hover(function() {
    var labelWidth = $(this).children('label').width() + 41;
    $(this).animate({width: labelWidth + 'px'}, 180);
  },
  function() {
    $(this).animate({width: '35px'}, 180);
  });

Also, I suppose a view of the actual markup might be helpful, so here you go:

<ul class="service-generator">
  <li id="[service-name]" class="full-service-wrapper photo">
    <label class="icon-name" for="[service-name]-checkbox">[service-name]</label>
    <div class="icon-wrapper">
      <input type="checkbox" checked="checked" name="[service-name]" id="[service-name]-checkbox"><img alt="[service-name]" title="[service-name]" src="[service-name].ico">
    </div>
  </li>
</ul>

And here's an image displaying the result: enter image description here

1

There are 1 best solutions below

1
On BEST ANSWER

The way to do this is by having your gray rounded border div containers be positioned absolute within the li tags with position relative. Then, you adjust the width of the absolutely positioned gray border div as they hover. You'll also likely to need to adjust z-indexes as well on mouseover/mouseout to control overlapping.