超链接解决头部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;
}
}
});

posted on 2015-04-28 11:39  唐红波  阅读(401)  评论(0编辑  收藏  举报

导航