Note that there are some explanatory texts on larger screens.

plurals
  1. POjQuery animate problem, solution added
    primarykey
    data
    text
    <p>I am working on a nav menu the markup structure is below, the span element is added on document.ready: -</p> <pre><code>&lt;ul id="menu"&gt; &lt;li class="menu act"&gt;Additional Fixture&lt;span class="active"&gt;&lt;/span&gt;&lt;/li&gt; &lt;li class="menu"&gt;list with sub menu &lt;ul class="sub-menu"&gt; &lt;li class="menu"&gt;Option one&lt;/li&gt; &lt;li class="menu"&gt;Option two&lt;/li&gt; &lt;li class="menu"&gt;Option three&lt;/li&gt; &lt;li class="menu"&gt;Option four&lt;/li&gt; &lt;li class="menu"&gt;Option five&lt;/li&gt; &lt;/ul&gt; &lt;/li&gt; &lt;li class="menu""&gt;Special Tricast&lt;/li&gt; </code></pre> <p></p> <p>The span is positioned absolute with a set width and height and contains an arrow image as the background.</p> <p>I'm using jQuery to animate the span/arrow image when a user clicks on a menu class to move the active span behind the selected menu (li) element as a visual indicator for their selection.</p> <p>This works fine when active (act) is set at the root li but if positioned anywhere else in the list for example: -</p> <pre><code>&lt;ul id="menu"&gt; &lt;li class="menu"&gt;Additional Fixture&lt;span class="active"&gt;&lt;/span&gt;&lt;/li&gt; **&lt;li class="menu act"&gt;list with sub menu&lt;/li&gt;** &lt;/ul&gt; </code></pre> <p>The arrow is positioned correctly when the document loads but doesn't move to the correct selection when clicked by a user. I've tried both position and offset for my divLocation variable, and i'm currently using position as offset fails to work even at root.</p> <p>I'm basically wanting the arrow to be set depending on what page the user has navigated to, so the animation needs to work from whatever starting position regardless of the length or position of the list.</p> <p>I've trawled the forums and tried a few things but i'm stumped to be honest and would greatly appreciate any assistance!!</p> <p>Below is the jQuery code for animating the span/arrow image: -</p> <pre><code>var divLocation = $(this).position(); $("span.active").animate({ 'top': divLocation.top + topOffset, 'left': divLocation.left + leftOffset }, animationSpeed, "linear", function(){ $(selectedElement).addClass("text-light"); $(selectedElement).fadeTo("100", opacityIn); }); </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