超链接解决头部fixed问题

///////////超链接解决头部fixed问题


$('a[href*=#]').click(function () {
var top1 = $(".header").height(), top2 = $(".navigation").height(),l=top1+top2;
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) {
var targetOffset = $target.offset().top-l;
var obj = document.documentElement;
if (jQuery.browser.safari)
obj = document.body
if (jQuery.browser.msie)
obj = 'html';
$(obj).animate({ scrollTop: targetOffset }, 1000);
return false;
}
}
});

原文地址:https://www.cnblogs.com/tanghongbo/p/4462567.html