2010-09-12 91 views
4

我有一個網站與Ajax加載的內容。現在我想要實現jQuery address plugin以獲得更好的用戶體驗和搜索引擎優化爬行。幫助與jQuery地址插件

用這一行$.address.value($(this).attr('href'));地址改變的東西有用,但我該如何做歷史支持,抓取等?我不得不這樣做,但是什麼?我試圖把$("#content").load(toLoad,'',showNewContent)和其他一千件事情,其中​​不幸的是沒有結果。

的文檔是真窮:http://www.asual.com/jquery/address/docs/

這是我的代碼:

$('a:not([href^=http])').click(function() { 

    var toLoad = $(this).attr('href') + " #ajaxedContent"; 

    $("#content").fadeOut(600,loadContent); 

    $("#load").remove(); 
    $('#logo').append('<div id="load"></div>'); 
    $("#load").fadeIn(100); 

    $.address.value($(this).attr('href')); 

    function loadContent() { 
     $("#content").load(toLoad,'',showNewContent) 
    } 

    function showNewContent() { 
     // Capture the final dimensions of the content element and animate, finally fade content in 
     $("#limit").animate({height: $("#content").height()},600,'easeInOutQuad',function() { 
      $("#content").fadeIn(600,hideLoader); 
      callback(); 
     }); 
    } 

    function hideLoader() { 
     $("#load").fadeOut(300); 
    } 

    return false; 
}); 

的基本原理是這樣的:

$.address.change(function(event) { 
    // do something depending on the event.value property, e.g. 
    // $('#content').load(event.value + '.xml'); 
}); 

$('a').click(function() { 
    $.address.value($(this).attr('href')); 
}); 

任何幫助將是非常讚賞。謝謝。

回答

3

這樣,它的工作原理:

$.address.init(function(event) { 

    $('a:not([href^=http])').address(); 

}).change(function(event) { 

    var toLoad = event.path + " #ajaxedContent"; 

    $("#content").fadeOut(600,loadContent); 

    $("#load").remove(); 
    $('#logo').append('<div id="load"></div>'); 
    $("#load").fadeIn(100); 

    function loadContent() { 
     $("#content").load(toLoad,'',showNewContent) 
    } 

    function showNewContent() { 
     // Capture the final dimensions of the content element and animate, finally fade content in 
     $("#limit").animate({height: $("#content").height()},600,'easeInOutQuad',function() { 
      $("#content").fadeIn(600,hideLoader); 
      callback(); 
     }); 
    } 

    function hideLoader() { 
     $("#load").fadeOut(300); 
    } 

    return false; 
}); 
+0

解決了!問題是,它無法識別頁面選擇。所以我改變了「$(this).attr('href')」與「event.path」。有用。 – Thomas 2010-09-19 23:46:22