Note that there are some explanatory texts on larger screens.

plurals
  1. POJavaScript if statement help needed
    primarykey
    data
    text
    <p>I'm using JavaScript to achieve a preview box when hovering over a list. I'll show you my code and then a live website on how it works, then I will say the problem.</p> <p>HTML</p> <pre><code>&lt;div id="content"&gt; &lt;div id="theDiv"&gt;&lt;h1&gt;Custom &lt;/h1&gt;&lt;/div&gt; &lt;div id="theDiv1"&gt;&lt;h1&gt;Custom One&lt;/h1&gt; &lt;/div&gt; &lt;div id="theDiv2"&gt;&lt;h1&gt;Custom Two&lt;/h1&gt;&lt;/div&gt; &lt;div id="theDiv3"&gt;&lt;h1&gt;Custom Three&lt;/h1&gt;&lt;/div&gt; &lt;div id="theDiv4"&gt;&lt;h1&gt;Custom Four&lt;/h1&gt;&lt;/div&gt; &lt;div id="theDiv5"&gt;&lt;h1&gt;Custom Five&lt;/h1&gt;&lt;/div&gt; &lt;div id="theDiv6"&gt;&lt;h1&gt;Custom Six&lt;/h1&gt;&lt;/div&gt; &lt;div id="theDiv7"&gt;&lt;h1&gt;Custom Seven&lt;/h1&gt;&lt;/div&gt; &lt;ul id="nav"&gt; &lt;li&gt;&lt;a href="#"&gt;&lt;b&gt;Austria &gt;&lt;/b&gt;&lt;/a&gt; &lt;br/&gt; &lt;ul&gt; &lt;li&gt;&lt;a href="#" class="theLink"&gt;Factsheet &lt;/a&gt;&lt;/li&gt;&lt;br/&gt; &lt;li&gt;&lt;a href="#" class="theLink1"&gt;Stylesheet &lt;/a&gt;&lt;/li&gt;&lt;br/&gt; &lt;li&gt;&lt;a href="#" class="theLink2"&gt;References &lt;/a&gt;&lt;/li&gt;&lt;br/&gt; &lt;/ul&gt; &lt;/li&gt; &lt;li&gt;&lt;a href="#"&gt;&lt;b&gt;Switzerland &gt;&lt;/b&gt;&lt;/a&gt; &lt;br/&gt; &lt;ul&gt; &lt;li&gt;&lt;a href="#" class="theLinka"&gt;Factsheet &lt;/a&gt;&lt;/li&gt;&lt;br/&gt; &lt;li&gt;&lt;a href="#" class="theLinka1"&gt;Stylesheet &lt;/a&gt;&lt;/li&gt;&lt;br/&gt; &lt;li&gt;&lt;a href="#" class="theLinka2"&gt;References &lt;/a&gt;&lt;/li&gt;&lt;br/&gt; &lt;/ul&gt; &lt;/li&gt; &lt;li&gt;&lt;a href="#"&gt;&lt;b&gt;Explanation Page &gt;&lt;/b&gt;&lt;/a&gt; &lt;br/&gt; &lt;ul&gt; &lt;li&gt;&lt;a href="#" class="theLinkb"&gt;Stylesheet &lt;/a&gt;&lt;/li&gt;&lt;br/&gt; &lt;li&gt;&lt;a href="#" class="theLinkb1"&gt;References &lt;/a&gt;&lt;/li&gt;&lt;br/&gt; &lt;/ul&gt; &lt;/li&gt; &lt;/ul&gt; &lt;/div&gt; </code></pre> <p>CSS</p> <pre><code>ul { padding-left:10px; list-style: none; width:150px; } ul li { position: relative; left:10px; width:148px; } li ul { position: relative; display:none; } /* Styles for Menu Items */ ul li a { display:block; text-decoration: none; line-height:2em; height:2em; padding:0 5px; color:#666; } a:hover {color:#999;} li ul li {width:139px; } li.on ul { display:block; } li.off ul{display:none; } .linkhover:hover {text-decoration:underline; } .linkxp:hover {text-decoration:underline; } #theDiv, #theDiv1, #theDiv2, #theDiv3, #theDiv4, #theDiv5, #theDiv6, #theDiv7, #theDiv8 { padding:10px; float:right; margin:0px 50px 0 0; width:300px; height:500px; border:1px solid #000; display:none; } </code></pre> <p>JavaScript</p> <pre><code>$(window).load(function(){ $(".theLink").hover( function () { $("#theDiv").fadeIn(); }, function () { $("#theDiv").fadeOut(); } ); }); $(window).load(function(){ $(".theLink1").hover( function () { $("#theDiv1").fadeIn(); }, function () { $("#theDiv1").fadeOut(); } ); }); $(window).load(function(){ $(".theLink2").hover( function () { $("#theDiv2").fadeIn(); }, function () { $("#theDiv2").fadeOut(); } ); }); $(window).load(function(){ $(".theLinka").hover( function () { $("#theDiv3").fadeIn(); }, function () { $("#theDiv3").fadeOut(); } ); }); $(window).load(function(){ $(".theLinka1").hover( function () { $("#theDiv4").fadeIn(); }, function () { $("#theDiv4").fadeOut(); } ); }); $(window).load(function(){ $(".theLinka2").hover( function () { $("#theDiv5").fadeIn(); }, function () { $("#theDiv5").fadeOut(); } ); }); $(window).load(function(){ $(".theLinkb").hover( function () { $("#theDiv6").fadeIn(); }, function () { $("#theDiv6").fadeOut(); } ); }); $(window).load(function(){ $(".theLinkb1").hover( function () { $("#theDiv7").fadeIn(); }, function () { $("#theDiv7").fadeOut(); } ); }); </code></pre> <p>Here is a link to a live view; <a href="http://tubebackgrounds.co.uk/uni/demo/explanation.html#" rel="nofollow">http://tubebackgrounds.co.uk/uni/demo/explanation.html#</a></p> <p>As you can see, if you hover over the list style too quickly when they are being displayed, the other ones show up. I'm wondering if it is possible to use an if statement so only one </p> <pre><code>$(window).load(function(){ $(".theLink").hover( function () { $("#theDiv").fadeIn(); }, function () { $("#theDiv").fadeOut(); } ); }); </code></pre> <p>can be enabled at once? Or maybe a way to make the fadeIn and fadeOut quicker.</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