首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >jquery fadein在子div元素中不fadein

jquery fadein在子div元素中不fadein
EN

Stack Overflow用户
提问于 2010-02-06 20:08:04
回答 1查看 5K关注 0票数 2

我有一个看似简单的问题。当我单击按钮时,我使用jquery淡入/淡出标签为#home的div中的一些内容。

我的问题是,如果我在#home div...whenever中创建了一个子DIV,我单击了#home按钮来淡入,子DIV的内容不会淡入。

但是,任何子对象,"p“或"img”都可以正常地淡入淡出,但不包括子对象"div“中的内容。请帮帮我!!

CSS:

代码语言:javascript
复制
#home {
    display: block;
    padding: 30px;
}
#home-button {
    opacity: 1.0;
    border-bottom: 1px solid black;
}
#about {
    display: none;
   padding: 30px;
}
#about-button {
    opacity: 0.5;
    border-bottom: 1px solid black;
}

JS:

代码语言:javascript
复制
$("#page-wrap div.button").click(function () {
    $clicked = $(this);

    // if the button is not already "transformed" AND is not animated
    if ($clicked.css("opacity") != "1" && $clicked.is(":not(animated)")) {
        $clicked.animate({
            opacity: 1,
            borderWidth: 5
        }, 600);

        // each button div MUST have a "xx-button" and the target div must have an id "xx"
        var idToLoad = $clicked.attr("id").split('-');

        //we search trough the content for the visible div and we fade it out
        $("#content").find("div:visible").fadeOut("fast", function () {
            //once the fade out is completed, we start to fade in the right div
            $(this).parent().find("#" + idToLoad[0]).fadeIn();
        })
    }

    //we reset the other buttons to default style
    $clicked.siblings(".button").animate({
        opacity: 0.5,
        borderWidth: 1
    }, 600);
});
EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2010-02-06 20:25:22

更改此设置:

代码语言:javascript
复制
$("#content").find("div:visible").fadeOut("fast", function(){
    //once the fade out is completed, we start to fade in the right div
    $(this).parent().find("#"+idToLoad[0]).fadeIn();
})

要这样做:

代码语言:javascript
复制
$("#content").children("div:visible").fadeOut("fast", function(){
    //once the fade out is completed, we start to fade in the right div
    $(this).parent().find("#"+idToLoad[0]).fadeIn();
})

你的.fadeOut()正在淡出子在其中的div,任何后代div...it听起来像是你只想隐藏直接的子级,然后淡入适当的子级,这将会做到这一点。如果这还不能解决问题,请告诉我。

票数 2
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/2213018

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档