元素完全可见后调用脚本

时间:2012-06-27 15:43:49

标签: jquery mcustomscrollbar

我正在使用下面的脚本在另一个内部加载一个隐藏的div:

$(document).ready(function(){
    $(function() {
        $('#menu a').click(function(e) {
            e.preventDefault();
            $('#menu a').removeClass("selected");
            $(this).addClass("selected");
            var h = $(this).attr('href');
            $("#conteudo").fadeOut("slow", function() {
                $(this).html($(h).html()).fadeIn("slow");
            });
        });
 });

但是在某些页面中,我使用了一些mCustomScrollbar,只有在不隐藏div时才有效。所以我需要在div完全可见之后调用脚本。我怎么能用上面的代码呢?

这是scrollBar脚本调用:

$("#mcs_container").mCustomScrollbar("vertical",400,"easeOutCirc",1.05,"auto","yes","yes",10);

在脚本页面中,它有这个示例代码,但我的脚本加载对整个菜单都有效......这个例子是设置他想要携带的页面。我能说清楚吗?

$("#mcs_container .content").load("new.html", function(){
    $("#mcs_container").mCustomScrollbar("vertical",400,"easeOutCirc",1.05,"auto","yes","yes",10);
});

1 个答案:

答案 0 :(得分:1)

您可以将回调函数传递给动画结束后将执行的.fadeIn()函数(使<div>可见)。看起来应该是这样的:

$("#conteudo").fadeOut("slow", function() {
    $(this).html($(h).html()).fadeIn("slow", function() {
        $("#mcs_container").mCustomScrollbar("vertical",400,"easeOutCirc",1.05,"auto","yes","yes",10);
    });
});
相关问题