目录
锚点向下偏移

//锚点向下偏移
点击a链接后,含有锚点的div显示位置,距离浏览器顶部的间距

1
2
3
4
5
6
7
$('a[href^=#][href!=#]').click(function () {
var target = document.getElementById(this.hash.slice(1));
if (!target) return;
var targetOffset = $(target).offset().top - 120; //120为离浏览器顶部的距离
$('html,body').animate({scrollTop: targetOffset}, 400);
return false;
});

www.foryh.com

文章作者: 艾小逗
文章链接: http://foryh.com/2018/09/03/锚点向下偏移,在浏览器顶部靠下显示/
版权声明: 本博客所有文章除特别声明外,均采用 CC BY-NC-SA 4.0 许可协议。转载请注明来自 艾小逗
打赏
  • 微信
  • 支付寶