【发布时间】:2014-01-01 20:57:03
【问题描述】:
这是一个例子,它显示了当按钮被点击时不同 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();
});
});
【问题讨论】:
-
您可以简单地显示/隐藏 div
标签: javascript jquery css