Results 1 to 2 of 2

Thread: fade and change z-index

  1. #1
    Join Date
    Oct 2011
    Posts
    20
    Thanks
    1
    Thanked 0 Times in 0 Posts

    Default fade and change z-index

    hi all,

    hoping that someone can answer a question for me - i am currently trying to get a bunch of divs to fade between each other when a link is clicked.
    the basics seem to be working fine - but when i add more complex content to the divs - i seem to run into more problems.

    this is the script i have
    Code:
    <script type='text/javascript'>//<![CDATA[
    $(window).load(function(){
    $('#show2').click(function() {
      $('#mirza1, #mirza3').fadeOut(500);
      $('#mirza2').fadeIn(500);
    });
    
    $('#show3').click(function() {
      $('#mirza1, #mirza2').fadeOut(500);
      $('#mirza3').fadeIn(500);
    });
    
    $('#show1').click(function() {
      $('#mirza2, #mirza3').fadeOut(500);
      $('#mirza1').fadeIn(500);
    });
    
    
    
    });//]]> 
    
    </script>
    and it all does what it says - but... when the div/content gets faded out it still seems to be responding to mouse movements. i have some mouse reactive content in the divs and on fadein they aren't where they should be - as if they have already been reacting to the mouse movement (if you know what i mean?)

    is there anyway of adding some z-index reference to it - so when faded it drops to the lowest z-index level? or maybe hide and then remove from the stage altogether... (or would the latter mean that the divs content would need to reload? not just appear?)

  2. #2
    Join Date
    Mar 2005
    Location
    SE PA USA
    Posts
    30,495
    Thanks
    82
    Thanked 3,449 Times in 3,410 Posts
    Blog Entries
    12

    Default

    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.
    - John
    ________________________

    Show Additional Thanks: International Rescue Committee - Donate or: The Ocean Conservancy - Donate or: PayPal - Donate

Similar Threads

  1. Ultimate Fade Slideshow Z-index Question
    By moez in forum Dynamic Drive scripts help
    Replies: 5
    Last Post: 01-10-2014, 04:16 PM
  2. Resolved Z-index problem with Ultimate Fade-in slideshow
    By Paramasivan in forum Dynamic Drive scripts help
    Replies: 5
    Last Post: 09-17-2011, 02:42 AM
  3. Resolved Ultimate Fade-in slideshow z-index issue
    By mobius2000 in forum Dynamic Drive scripts help
    Replies: 4
    Last Post: 07-27-2010, 11:07 AM
  4. Ultimate Fade Slideshow and z-index when behind div popup
    By dmfrey in forum Dynamic Drive scripts help
    Replies: 1
    Last Post: 06-28-2010, 07:43 PM
  5. Want the index page loaded to fade in
    By ian_6500 in forum Looking for such a script or service
    Replies: 0
    Last Post: 01-26-2010, 04:23 AM

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •