Note that there are some explanatory texts on larger screens.

plurals
  1. POmanipulating image z-index with jQuery
    text
    copied!<p>I have a row of 160x160px floated images resized to 100x100px by the browser.</p> <p>On hover, the images animate to their usual size and margins are manipulated to keep them in the same place.</p> <p>What I want to achieve next is to have the enlarged image move to the front, then back again after the hover event. I'm try to achieve this by adding and removing a class where z-index is 100.</p> <p>The HTML is:</p> <pre><code> &lt;div id="content_top"&gt; &lt;img class="thumbnail" src="images/thumbs/thumb1.jpg" width="100" height="100" border="0" alt=""/&gt; &lt;img class="thumbnail" src="images/thumbs/thumb2.jpg" width="100" height="100" border="0" alt=""/&gt; &lt;img class="thumbnail" src="images/thumbs/thumb3.jpg" width="100" height="100" border="0" alt=""/&gt; &lt;img class="thumbnail" src="images/thumbs/thumb4.jpg" width="100" height="100" border="0" alt=""/&gt; &lt;img class="thumbnail" src="images/thumbs/thumb5.jpg" width="100" height="100" border="0" alt=""/&gt; &lt;/div&gt; </code></pre> <p>With the CSS:</p> <pre><code>#content_top { height: 210px; } #content_top img{ float:left; padding: 0 0 0 10px; } .ontop { z-index: 100; } </code></pre> <p>The jQuery I'm using is:</p> <pre><code>$('#content_top img').hover(function(){ $(this).filter(':not(:animated)').animate({ 'width' : '160px', 'height' : '160px', 'marginLeft' : '-30px', 'marginRight' : '-30px', 'marginBottom' : '-30px' }, 'fast', 'linear' ).addClass('ontop'); }, function(){ $(this).animate({ 'width' : '100px', 'height' : '100px', 'marginLeft' : '0px', 'marginRight' : '0px', 'marginBottom' : '0px' }, 'fast', 'linear' ).removeClass('ontop'); }); </code></pre> <p>All works fine, except the z-index part. I've tested that the class is being added, and it is. Tried various ways of positioning the images, even wrapping them in container divs and changing the z-index of those.</p> <p>What have I missed?</p> <p>Thanks.</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload