Animated Jquery Flyout Menu
<p>I want to make my JQuery menu have a simple animation when the user clicks on a link. I have an arrow pointing at the link clicked, however I want the arrow to animate between clicks. If the user clicks Link1 the arrow slides to the right, if the user clicks link 2 the arrow slides back to the left. I know I can use ".animate". But i haven't been able to get that to work. </p>

<p>HTML/CSS</p>

<pre><code>&lt;!doctype html&gt;

&lt;html&gt;
&lt;head&gt;
&lt;title&gt;Demo&lt;/title&gt;

&lt;meta http-equiv="X-UA-Compatible" content="chrome-1"&gt;
&lt;meta name="viewport" content="width=1240"&gt;

&lt;style type="text/css"&gt;
 #flyout
{   margin: 0;
    padding: 0}

    #flyout li
    {   float: left;
        list-style: none;
        font: 12px Tahoma, Arial}

    #flyout li a
    {   display: block;
        background: #20548E;
        padding: 5px 12px;
        text-decoration: none;
        border-right: 1px solid white;
        width: 80px;
        color: #EAFFED;
        white-space: nowrap}

    #flyout li a:hover
    {   background: #1A4473}

        #flyout li ul
        {   margin: 0;
            padding: 0;
            position: absolute;
            left: 8px;
            display: none;
            padding-top: 10px;
            border-top: 1px solid white}

        #flyout li ul li
        {   float: none;
            display: inline;}

        #flyout li ul li a
        {   width: auto;
            background: #9F1B1B;
            width: 400px;}

        #flyout li ul li a:hover
        {   background: #7F1616}
&lt;/style&gt;
&lt;/head&gt;
&lt;body&gt;
&lt;img class="arrow" src="img/arr.png" alt="arrow" style="position:absolute; top:32px; display:none;"&gt;
&lt;ul id="flyout"&gt;
    &lt;li class="me a"&gt;&lt;a href="#"&gt;Link 1&lt;/a&gt;
        &lt;ul class="ul_a"&gt;
            &lt;li&gt;&lt;a href="#"&gt;Sub A&lt;/a&gt;&lt;/li&gt;
            &lt;li&gt;&lt;a href="#"&gt;Sub B&lt;/a&gt;&lt;/li&gt;
            &lt;li&gt;&lt;a href="#"&gt;Sub C&lt;/a&gt;&lt;/li&gt;
        &lt;/ul&gt;
    &lt;/li&gt;
    &lt;li class="me b"&gt;&lt;a href="#"&gt;Link 2&lt;/a&gt;
        &lt;ul class="ul_b"&gt;
            &lt;li&gt;&lt;a href="#"&gt;Sub D&lt;/a&gt;&lt;/li&gt;
            &lt;li&gt;&lt;a href="#"&gt;Sub E&lt;/a&gt;&lt;/li&gt;
            &lt;li&gt;&lt;a href="#"&gt;Sub F&lt;/a&gt;&lt;/li&gt;
        &lt;/ul&gt;
    &lt;/li&gt;
&lt;/ul&gt;
</code></pre>

<p>
</p>

<p>JQuery</p>

<pre><code>(function(){  

var closetimer = 0;
var menuitem = 0;
var arrow = $('.arrow');

function animate_right () {
   var ele = $('.a'); 
   var pos = ele.offset(); 
   var left = pos.left;
   var total = left+48;
   arrow.show().css('left', total);
}

function animate_left () {
   var ele = $('.b'); 
   var pos = ele.offset(); 
   var left = pos.left;
   var total = left+48;
   arrow.show().css('left', total);
}

function arrow_hide () {
   arrow.hide()
}

function flyout_open(event)
{
   flyout_close();
   var submenu = $(this).find('ul');
   menuitem = submenu.fadeIn(200);  
    if(submenu.hasClass('ul_a')){
        animate_right();

        return false;

    } else if (submenu.hasClass('ul_b')) {
        animate_left();

        return false;
    }

    return true;
}

function flyout_close()
{  arrow_hide(); if(menuitem) menuitem.fadeOut(200);}

$(document).ready(function()
{  $('#flyout li').bind('click', flyout_open);
});

(document).onclick = flyout_close;


})();
</code></pre>
