Note that there are some explanatory texts on larger screens.

plurals
  1. POfading divs in and out, depending on an "active" class
    primarykey
    data
    text
    <p>This is related to my previous question <a href="https://stackoverflow.com/questions/2338770/jquery-rollovers-and-active-states">here</a>. </p> <p>I want 4 divs (absolute with z-indexes) to start off as being invisible (faded out), and when a link is clicked, the related div fades in. When the same link is clicked, the related div fades out. When a different link is clicked, the first div fades out and the second div fades in.</p> <p>There is a "covering" div ("#contents_screen") over these 4 absolute divs. This will probably form my "home" page, so it is required despite seemingly having no purpose.</p> <p>I got it working to a certain extent, but no cigar. I'd appreciate some help. Thank you very much for looking!</p> <pre><code> &lt;!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"&gt; &lt;html xmlns="http://www.w3.org/1999/xhtml"&gt; &lt;head&gt; &lt;meta http-equiv="Content-Type" content="text/html; charset=UTF-8" /&gt; &lt;title&gt;Untitled Document&lt;/title&gt; &lt;style&gt; #contents { width:500px; margin:auto; height:400px; border:1px solid black; position:relative; } #contents_screen { position:absolute; width:500px; height:400px; background:#fff; z-index:50; } #contents_folio, #contents_services, #contents_about, #contents_contact { position:absolute; width:500px; background:#fff; color:#333; z-index:20; }&lt;/style&gt; &lt;script src="http://ajax.googleapis.com/ajax/libs/jquery/1.4/jquery.min.js" type="text/javascript" charset="utf-8"&gt;&lt;/script&gt; &lt;script type="text/javascript"&gt; $(document).ready(function(){ $("a.rollover").fadeTo(1,0.5); $(".screen").fadeTo(1,0); function identify_active(){ var activeID = $(".active").attr("id"); var active_screen; $("#contents_screen").fadeTo(1,1); $(active_screen).fadeTo(1,0); if (activeID=="folio") { active_screen="contents_folio";} else { if (activeID=="services") { active_screen="contents_services";} else { if (activeID=="about") { active_screen="contents_about";} else { if (activeID=="contact") { active_screen="contents_contact"; }}}} $(active_screen).fadeTo(1,1); $("#contents_screen").fadeTo(1,0); } $("a.rollover").hover( function(){$(this).fadeTo("fast",1);}, function(){ if(!$(this).hasClass('active')) { $(this).fadeTo("fast",0.5);} }); $("a.rollover").click(function(){ if($('.active').length &gt; 0) { if($(this).hasClass('active')) { $(this).removeClass("active"); $(this).fadeTo("fast",0.5); } else { $(".active").fadeTo("fast",0.5); $(".active").removeClass("active"); $(this).addClass("active"); $(this).fadeTo("fast",1); identify_active(); } } else { $(this).addClass("active"); $(this).fadeTo("fast",1); identify_active(); } return false; }); }); &lt;/script&gt; &lt;/head&gt; &lt;body&gt; &lt;div id="stage"&gt; &lt;div id="menu"&gt; &lt;ul id="menu"&gt; &lt;li&gt;&lt;a class="rollover" id="folio" href="#"&gt;folio&lt;/a&gt;&lt;/li&gt; &lt;li&gt;&lt;a class="rollover" id="services" href="#"&gt;services&lt;/a&gt;&lt;/li&gt; &lt;li&gt;&lt;a class="rollover" id="about" href="#"&gt;about&lt;/a&gt;&lt;/li&gt; &lt;li&gt;&lt;a class="rollover" id="contact" href="#"&gt;contact&lt;/a&gt;&lt;/li&gt; &lt;/ul&gt; &lt;/div&gt; &lt;div id="contents"&gt; &lt;div id="contents_screen"&gt;screen&lt;/div&gt; &lt;div id="contents_folio" class="screen"&gt;folio&lt;/div&gt; &lt;div id="contents_services" class="screen"&gt;services&lt;/div&gt; &lt;div id="contents_about" class="screen"&gt;about&lt;/div&gt; &lt;div id="contents_contact" class="screen"&gt;contact&lt;/div&gt; &lt;/div&gt;&lt;!--contents--&gt; &lt;/div&gt;&lt;!--stage--&gt; &lt;/body&gt; &lt;/html&gt; </code></pre>
    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