【发布时间】:2016-11-04 23:16:34
【问题描述】:
我有固定的标题。当我点击锚链接时,它会在那个位置上。问题是我的固定标题的高度与该位置重叠。我想当我去某个锚点时,它的位置是 = 锚点 - 标题高度。
这是我的 javascript 代码:
<script> <!--Anchors-->
$(function() {
$('a[href*="#"]:not([href="#"])').click(function() {
if (location.pathname.replace(/^\//,'') == this.pathname.replace(/^\//,'') && location.hostname == this.hostname) {
var target = $(this.hash);
target = target.length ? target : $('[name=' + this.hash.slice(1) +']');
if (target.length) {
$('html, body').animate({
scrollTop: target.offset().top
}, 1000);
return false;
}
}
});
});
</script>
【问题讨论】:
-
能把你的html和css代码放上来
-
没有必要。
<a href="#somediv"> Link </a> <div id="somediv"> ... content </div>
标签: javascript jquery css html