0

私は少し違いを持っ​​てjQueryに垂直アコーディオンメニューを実装しようとしています。メインメニューの左側にある矢印とサブメニューの右側にある矢印をアニメートしたいと思います。

私はそれを視覚化できないかもしれませんが、私の問題は単純です。要素がクリックされたとき、その上部の位置を取得する必要がありますが、そのサブメニューが縮小または拡大しているため、要素をクリックした後にその位置が変更されました。

サブメニューがアニメーション化されて位置を変更した後、その要素の最新の位置を取得するにはどうすればよいですか?

以下のコードを見つけることができます。それはそれ自身を説明するかもしれません。

$("#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 に答える