码迷,mamicode.com
首页 > 其他好文 > 详细

超链接解决头部fixed问题

时间:2015-04-28 13:51:52      阅读:122      评论:0      收藏:0      [点我收藏+]

标签:

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

超链接解决头部fixed问题

标签:

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

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!