当ajax加载页面时,Jquery插件未加载

时间:2012-08-02 18:16:05

标签: ajax jquery jquery-plugins smooth-scrolling

我一直在研究这段代码。我正在尝试在库页面加载了ajax后实现SmoothDivScroll jquery插件。这是我用ajax的js。请注意,smoothdivscroll工作正常,无需使用ajax加载库。

$(document).ready(function(){

    $('.more').live('click',function(){
        var href = $(this).attr('href');
        if ($('#ajax').is(':visible')) {
            $('#ajax').css('display','block').animate({height:'1px'}).empty();
        }
        $('#ajax').css('display','block').animate({height:'380px'},function(){
            $('#ajax').html('<img class="loader" src="images/loader.gif" alt="">');
            $('#ajax').load('content.php #'+href, function(){
                $('#ajax').hide().fadeIn().highlightFade({color:'#717171'});
            });
        });
        return true;
    });

    $("div#makeMeScrollable").smoothDivScroll({
        mousewheelScrolling: true,
        manualContinuousScrolling: true,
        visibleHotSpotBackgrounds: "always",
        autoScrollingMode: "onstart"
    });

});

更新:虽然@Mathletics的答案确实通过在回调中调用插件来加载插件,但smoothscrollingdiv并不是那么顺利。图片不是内​​联的,滑动非常不稳定。它完美无缺,无需加载它。下面我提供了关于ajax和没有它的样子的链接。

Ajax已加载:select gallery from the menu

没有Ajax:This is how the gallery is supposed to be

1 个答案:

答案 0 :(得分:1)

smoothDivScroll电话移至您的回叫中。

$(document).ready(function(){

    $('.more').live('click',function(){
        var href = $(this).attr('href');
        if ($('#ajax').is(':visible')) {
            $('#ajax').css('display','block').animate({height:'1px'}).empty();
        }
        $('#ajax').css('display','block').animate({height:'380px'},function(){
            $('#ajax').html('<img class="loader" src="images/loader.gif" alt="">');
            $('#ajax').load('content.php #'+href, function(){
                $('#ajax').hide().fadeIn().highlightFade({color:'#717171'});
                    $("div#makeMeScrollable").smoothDivScroll({
                    mousewheelScrolling: true,
                    manualContinuousScrolling: true,
                    visibleHotSpotBackgrounds: "always",
                    autoScrollingMode: "onstart"
                });

            });
        });
        return true;
    });


});