繁体   English   中英

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

[英]show content of each page when link us clicked

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

麻烦: 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();
    });
});

如果加载了内容,则可以隐藏显示所需内容。 如果按页面表示您是外部页面,则可以使用ajax调用来调用资源:

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

http://jsfiddle.net/2LCM4/

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM