使用 jQuery Address 插件的帮助

4
我有一个使用ajax加载内容的网站。现在我想要实现jQuery地址插件以获得更好的用户体验和SEO抓取。
使用这行代码$.address.value($(this).attr('href'));,地址更改功能有效,但如何实现历史支持、抓取等功能呢?
需要使用$.address.change(function(event){...});来完成一些操作,但是具体如何操作呢?我已经尝试将$("#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'));
});

任何帮助都将不胜感激。谢谢。
1个回答

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;
});

解决了!问题在于它无法识别页面选择。所以我用"event.path"替换了"$(this).attr('href')"。现在它可以正常工作了。 - Thomas

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接