Note that there are some explanatory texts on larger screens.

plurals
  1. POJQuery Animate Z-Index?
    primarykey
    data
    text
    <p>In my page I have different menu items that trigger different corresponding pictures. The <code>z-index</code> switches the corresponding picture to the top. Here is the code:</p> <pre><code>$(document).ready(function(){ var doorOpen = false; $("a[href=#andrew]").click(function() { if (doorOpen) { // set animation duration for door close, based on actually needed to animate the door closed or not var duration = 1500; } else { var duration = 0; } $("#rightdoor,#leftdoor").animate( {"marginLeft":"0px"}, {duration:duration, complete:function() { $('.pic2 .pic3 .pic4 .pic5').css('zIndex', 1); //puts wrong pics in back $('.pic1').css('zIndex', 2); //brings right pic into view $('#rightdoor').animate({ //opens doors again marginLeft: "150px", }, 1500); $('#leftdoor').animate({ marginLeft: "-150px", }, 1500); } } ); doorOpen = true; }); $("a[href=#bugz]").click(function() { if (doorOpen) { // set animation duration for door close, based on actually needed to animate the door closed or not var duration = 1500; } else { var duration = 0; } $("#rightdoor,#leftdoor").animate( {"marginLeft":"0px"}, {duration:duration, complete:function() { $('.pic1 .pic3 .pic4 .pic5').css('zIndex', 1); //puts wrong pics in back $('.pic2').css('zIndex', 2); //brings right pic into view $('#rightdoor').animate({ //opens doors again marginLeft: "150px", }, 1500); $('#leftdoor').animate({ marginLeft: "-150px", }, 1500); } } ); doorOpen = true; }); }); </code></pre> <p>The problem is that the <code>z-index</code> works but only once per menu item it seems. If you initially click <code>#andrew</code>, it brings pic1 to the top and if you click <code>#bugz</code> it brings pic2 to the top. However, if you click <code>#andrew</code> again it animates the code before and after the <code>.css(z-index)</code> change but does not change the <code>z-index</code> to bring pic1 back to the top.</p> <p>I am new to Javascript/JQuery so please forgive me if I am missing something obvious</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

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