0

我在将标题中的链接滚动到标签时遇到问题。因为它是一个固定的标题,所以它会滚动到该区域,并且内容位于标题后面。如何将其修复到标题底部的位置?box-sizing: border-box;如果这与它有任何关系,我也在使用它。谢谢您的帮助。

这是jQuery:

$(".scrolltotag").click(function(event){        
    event.preventDefault();
    $('html,body').animate({scrollTop:$(this.hash).offset().top}, 600);
});

导航中的所有链接都有一个类scrolltotag和一个href="#tag"

4

2 回答 2

0

// 获取表头高度

var headerHeight = $(".header").height();

// 附加点击事件

$('a[href*=#]').bind("点击", function(e) { e.preventDefault();

var target = $(this).attr("href"); var scrollToPosition = $(target).offset().top - headerHeight;

$('html').animate({ 'scrollTop': scrollToPosition }, 600, function(){ window.location.hash = "" + target;

$('html').animate({ 'scrollTop': scrollToPosition }, 0); }); });

于 2014-01-27T06:56:44.470 回答
0

不过,我能够通过- $('header').outerHeight()$('html,body').animate({scrollTop:$(this.hash).offset().top感谢后添加来修复它!

于 2013-08-08T18:55:56.890 回答