链接我们点击时显示每个页面的内容

时间:2014-01-01 12:40:48

标签: javascript jquery css

以下是单击按钮时显示不同div的内容的示例。

Fidddle:http://jsfiddle.net/teddyrised/NHtvM/15/

而不是div,我想在点击链接时显示不同页面的内容。 一定不能出现滚动条。

页眉和页脚应保持固定。怎么做?

JS:

$(function () {
    // Scroll to function
    function scrollTo(ele) {
        $("html, body").animate({
            scrollTop: $(ele).offset().top - $("header").outerHeight()
        });
    }

    // Detect location hash
    if (window.location.hash) {
        scrollTo(window.location.hash);
    }

    // Detect click event
    $("header a[href^='#']").click(function (e) {
        var target = $(this).attr("href");
        scrollTo(target);
        e.preventDefault();
    });
});

1 个答案:

答案 0 :(得分:1)

如果加载了内容,您可以隐藏 - 显示您需要的内容。如果您通过页面表示外部页面,则可以使用ajax调用来调用该资源:

    $.ajax({
        url: "http://fiddle.jshell.net/user/login/",
        context: document.body
    }).done(function(data) {
        target.html(data);
        scrollTo(target);
    });

http://jsfiddle.net/2LCM4/

相关问题