开发者

why does .live not work in this script?

开发者 https://www.devze.com 2023-02-22 19:15 出处:网络
I got this script to dynamically load html in a div..however there\'s a problem when you load jquery functions and i found out .live is the way to fix it but when i try it doesn\'t work..what am i doi

I got this script to dynamically load html in a div..however there's a problem when you load jquery functions and i found out .live is the way to fix it but when i try it doesn't work..what am i doing wrong?

$(function() {

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


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

$(window).live('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({
                            heig开发者_如何学Pythonht: baseHeight + $mainContent.height() + "px"
                        });
                    });
                    $("nav a").removeClass("current");
                    $("nav a[href="+newHash+"]").addClass("current");
                });
            });


    };

});

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


});


   };

remove semicolon at the end of your event handler

0

精彩评论

暂无评论...
验证码 换一张
取 消