Smoothstate.js:防止标头重新加载,尽管这些链接触发了页面更改

时间:2015-08-05 00:30:25

标签: javascript jquery ajax smoothstate.js

smoothstate.js要求触发ajax调用的链接位于包含要更新内容的#main div中。但是,我需要标题和里面的链接保持从内容交换中省略,最好只重新加载指定的.content div中的内容。

有没有办法,使用smoothstate.js,以防止重新加载标题链接,尽管要求它们位于刷新的#main div内?

我有想法将内容div与onReady函数中返回的$ newContent对象分开。但是,虽然我能够分离出指定的div,但将返回的对象传递给html失败。

(function header_init() {

    $('#main').smoothState({
        anchors: 'a',
        blacklist: '.no-ajax',
        prefetch: true,
        cacheLength: 4,
        repeatDelay: 500,

        onStart: {
            duration: 300,
            render: function ($container) {
                $('html').addClass('animate-page-out');
                $('html').removeClass('animate-page-in');
            }
        },
        onReady: {
            duration: 300,
            // `$container` is a `jQuery Object` of the current smoothState container
            // `$newContent` is a `jQuery Object` of the HTML that should replace the existing container's HTML.
            render: function ($container, $newContent) {

                // Update the HTML on the page
                var content = $($newContent).find('.main-content');
                console.log($newContent);
                console.log($(content));
                // $container.html($newContent);
                $('.main-content').html($(content));
            }
        },
        onAfter: function ($container, $newContent) {
            // after page loads, all scripts must be re-initialize to account for any new DOM items
            $('html').addClass('animate-page-in');
            $('html').removeClass('animate-page-out');
        }
    });
}());

0 个答案:

没有答案