当使用$(window).bind('hashchange',onHashchange).trigger('hashchange')时,javascript无法正常工作;

时间:2015-12-16 06:24:06

标签: javascript php jquery html

我正在使用

$(function() {

var newHash      = "",
    $mainContent = $("#main-content"),
    $pageWrap    = $("#page-wrap"),
    baseHeight   = 0,
    $el;

$pageWrap.height($pageWrap.height());
baseHeight = $pageWrap.height() - $mainContent.height();

$("nav").delegate("a", "click", function() {
    window.location.hash = $(this).attr("href");
    return false;
});

$(window).bind('hashchange', function(){

    newHash = window.location.hash.substring(1);

    if (newHash) {
        $mainContent
            .find("#guts")
            .fadeOut(200, function() {
                $mainContent.hide().load(newHash + " #guts", function() {
                    $mainContent.fadeIn(200, function() {
                        $pageWrap.animate({
                            height: baseHeight + $mainContent.height() + "px"
                        });
                    });
                    $("nav a").removeClass("current");
                    $("nav a[href='"+newHash+"']").addClass("current");
                });
            });
    };

});

$(window).trigger('hashchange');

});

但已加载正文的javascript无效

我试过 window.addEventListener ,但它也无法正常工作

示例的参考是链接: https://css-tricks.com/dynamic-page-replacing-content/

0 个答案:

没有答案