开发者

Jquery toggle only fires once

开发者 https://www.devze.com 2023-01-10 17:35 出处:网络
I have the f开发者_JAVA技巧ollowing code which is used to slidein/out a div (shopping basket) on a page. However, the code will only fire once (open once, close once). Does the toggle need to be reset

I have the f开发者_JAVA技巧ollowing code which is used to slidein/out a div (shopping basket) on a page. However, the code will only fire once (open once, close once). Does the toggle need to be reset in some way?

$(document).ready(function(){

    var miniBasketHeight = -$('#minibasket div.outer').height();

    $('#minibasket a.opener').toggle(
        function(e) {
            console.log("open");
            e.preventDefault();
            $(this).parent().find('div.outer').animate({top: 0, opacity: 1 }, 700 );
        },
        function(e) {
            console.log(miniBasketHeight);
            e.preventDefault();
            $(this).parent().find('div.outer').animate({top: miniBasketHeight, opacity: 0 }, 700 );
        }
    );
});


This has now been resolved using slideToggle()

$(document).ready(function(){
    $('#minibasket a.opener').click(function(e) {
        e.preventDefault();
        $('div.outer').slideToggle('slow', function() {
            //Animation complete
        });
    });
});
0

精彩评论

暂无评论...
验证码 换一张
取 消