0

I am trying to implement a vertical accordion menu in jQuery with a little diffence. I want to animate an arrow at the left side of the main menus and an arrow at the right side of the sub menus.

I may not visualize it but my problem is simple. When an element clicked, i need to get its top position but its position changed after I clicked the element because its sub menu is shrinking or augmenting.

How can I get the latest position of that element after its submenu is animated and change its position?

You can find the code below. It may explain itself..

$("#firstpane p.menu_head").click(function(e)
{
    $('#larrow').hide();
    $(this).next("div.menu_body").slideToggle(300).siblings("div.menu_body").slideUp("slow");
    $('#bgImageContainer').show();
    $('.slidesContainer').hide();
    $('.slidesThumbs').hide();

    if($(this).hasClass('subcategory')){
        animateLeftArrow(this);
    }
});

function animateLeftArrow(item){
    var pos = $('#rarrow').css('top').replace(/[^-\d\.]/g, '');
    var itpos = $(item).position();
    if($(item).hasClass("first"))
        lastpos = itpos.top -202 + 9;
    else
        lastpos = itpos.top - 202;
    $('#rarrow').show();
    $('#rarrow').animate({
        top: lastpos
    });
}
4

2 回答 2

1
$('#rarrow').animate(
    { top: lastpos },
    1000,
    function(){
        console.log($(this).offset());
    }
);
于 2012-04-27T07:02:28.743 回答
0

您将希望在动画上使用回调函数。(http://api.jquery.com/animate/)

$('#rarrow').animate(
{
    alert("before");
}, 1000,
function()
{
    alert("after");
});
于 2012-04-27T06:19:11.060 回答