If my understanding is correct, you are looking to add transparency to the div
with a higher z-index
, and increase this transparency through an animation when a button is clicked. The final result should be that the initially upper div
ends up below the other one. To achieve this effect, adjustments will need to be made to both the z-index
and the opacity
CSS properties.
Based on your example scenario, consider the following HTML structure:
<button id="card">Swap</button>
<div id="map"> </div> <!-- Initially positioned below, moves up on click -->
<div id="info"> </div> <!-- Initially positioned above, moves down on click -->
Assuming both div
s are overlapping due to these CSS styles:
div {
position: absolute;
top: 50px;
left: 0px;
}
#map {
z-index: 5;
}
#info {
z-index: 10;
opacity: .8;
}
The event handler required to achieve the desired effect is as follows:
$('#card').on('click', function() {
$('#info').animate({opacity: 0}).css({'z-index': 5});
$('#map').css({'z-index': 10});
});
For further clarity, refer to this jsfiddle demonstration: http://jsfiddle.net/r7jh84nv/1/
It's worth mentioning that in the code from the provided link, the z-index
is not adjusted. Instead, the div with the higher index is hidden without modification.