开发者

jQuery fade out before fade in

开发者 https://www.devze.com 2023-01-23 13:55 出处:网络
I am making my portfolio, totally javascript based. http://portfolio.theadamgaskins.com/Portfolio/ My problem, is when you click one of the navigation buttons, the new page fades in at the same time

I am making my portfolio, totally javascript based. http://portfolio.theadamgaskins.com/Portfolio/

My problem, is when you click one of the navigation buttons, the new page fades in at the same time that the other page fades out. The current page should fade out before the new page fades in. Here's the code I'm using:

    $("#homeButton").click(function()
    {
        $('.page[id!="homePage"]').fadeOut('400', function()
        {
            $("#homePage").fadeIn('400');
        });
    });

This is out of context; feel free to View Source on the s开发者_运维百科ite.


This happens because some of the elements are already hidden, so their callbacks execute immediately...causing your simultaneous animation. To remedy this add :visible to your selector of elements you want to animate, like this:

$("#homeButton").click(function() {
    $('.page[id!="homePage"]:visible').fadeOut('400', function() {
        $("#homePage").fadeIn('400');
    });
});

This way you're not attaching an animation or problematic callback to the elements that are already hidden.

0

精彩评论

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