//锚点向下偏移
点击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