a标签的链接里加上#,div中给个id,名字需要一样,这样就能达到页面跳转效果,即锚点。
<a href="#form">锚点</a>
<div id="form">表格</div>
但有时默认的跳转位置与自己需要该锚点到达的位置有所偏移,这时就可以用js调整一下:
$('a').click(function () {
var target = $(this).attr('href'); // target获取的是a标签里的链接
$('html, body').animate({
scrollTop: $(target).offset().top - 100 //100为设置的偏移值
}, 500);
return false;
});
到这,就完美解决了偏移问题。
若有错误或不完整的地方,欢迎各位大佬指正!