以下是单击按钮时显示不同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();
});
});
答案 0 :(得分:1)
如果加载了内容,您可以隐藏 - 显示您需要的内容。如果您通过页面表示外部页面,则可以使用ajax调用来调用该资源:
$.ajax({
url: "http://fiddle.jshell.net/user/login/",
context: document.body
}).done(function(data) {
target.html(data);
scrollTo(target);
});