fix header offsetting an html anchor
I am trying to clean up the way my anchors work. I have a header that is fixed to the top of the page, so when you link to an anchor elsewhere in the page, the page jumps so the anchor is at the top of the page, leaving the content behind the fixed header.
My below code is working as i want it to work. The only is issue i am getting with IE8. When I click on a jump link, it jump past it rather than to the correct position.
Can i get any help to fix this in ie8?
<script>
! function(o, n) {
var t = function() {
var n = o(":target"),
t = 100;
n.length > 0 && o("html, body").stop().animate({
scrollTop: n.offset().top - t
}, 80)
};
o(n).on("hashchange load", function() {
t()
})
}(jQuery, window);
</script>
I used to fix this with css:
#anchor {
position: relative;
}
#anchor:after {
content: "";
position: absolute;
height: 80px;
width: 1px;
top: -80px;
left: 0;
}
80px is the top offset.
链接地址: http://www.djcxy.com/p/89006.html上一篇: 参考(命名锚点)在降价
下一篇: 修复标题偏移一个HTML锚点