The z-index stacking (zIndex in javascript, zIndex or quoted "z-index" for jQuery), is what's likely at issue here. But there is another way, you can move them around in the DOM, as whatever comes later, has a naturally occurring higher relative z-index. Also - if the divisions are all of the same dimensions, you don't have to be fading one in, while fading another out. You can simply move the next one that you want to be seen to the end of the parent element and then fade it in. It will cover the other(s). So, let's say you have:
HTML Code:
<div id="mirzacontainer">
<div id="mirza1"></div>
<div id="mirza2"></div>
<div id="mirza3"></div>
</div>
And all four of these divisions, including mirzacontainer are the same dimensions, and all three of the inner merza divisions are position absolute and display none to begin with. Then:
Code:
$(window).load(function(){
var $c = $('#mirzacontainer');
$('#show2').click(function() {
$c.append($('#mirza2').fadeIn(500, function(){$('#mirza1, #mirza3').hide();}));
});
$('#show3').click(function() {
$c.append($('#mirza3').fadeIn(500, function(){$('#mirza1, #mirza2').hide();}));
});
$('#show1').click(function() {
$c.append($('#mirza1').fadeIn(500, function(){$('#mirza2, #mirza3').hide();}));
});
});
Only I would do that on document load not window load, though if there are a lot of images, window load still might be best. And I would have one division shown immediately. Here's a working demo:
HTML Code:
<!DOCTYPE html>
<html>
<head>
<title></title>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<style type="text/css">
#mirzacontainer, #mirzacontainer div {
width: 100px;
height: 100px;
}
#mirzacontainer div {
position: absolute;
display: none;
background-color: #ffa;
}
span[id^=show] {
cursor: pointer;
}
</style>
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1/jquery.min.js"></script>
<script>
jQuery(function($){
var $c = $('#mirzacontainer');
$('#show2').click(function() {
$c.append($('#mirza2').fadeIn(500, function(){$('#mirza1, #mirza3').hide();}));
});
$('#show3').click(function() {
$c.append($('#mirza3').fadeIn(500, function(){$('#mirza1, #mirza2').hide();}));
});
$('#show1').click(function() {
$c.append($('#mirza1').fadeIn(500, function(){$('#mirza2, #mirza3').hide();}));
}).trigger('click');
});
</script>
</head>
<body>
<div id="mirzacontainer">
<div id="mirza1">Hello There!</div>
<div id="mirza2">My name is</div>
<div id="mirza3">John</div>
</div>
<span id="show1">1</span> <span id="show2">2</span> <span id="show3">3</span>
</body>
</html>
At least that's the basics.
Bookmarks