版权声明:本文为博主原创文章,未经博主允许不得转载。 https://blog.csdn.net/LiyangBai/article/details/83046662
原来的问题是:页面锚点跳转的时候div会调到顶部去,正好被导航挡住了!
html代码:
<a href="#idName">button</a>
<div id="idName">hahahahahhhhhhhhhhh</div>
于是设置如下JS代码:
$(function(){
if(location.hash){
var target = $(location.hash);
if(target.length == 1){
$('html,body').animate({scrollTop: '0'},500);
}
}
})
现在跳转的时候div已经不会被顶上去了,但是页面会闪烁一下!!!难受香菇.....怎么办???
====================================================================================================
有待尝试:
使用bootstrap的affix.js插件实现,引入affix.js
用法一:通过data属性
<div data-spy="affix" data-offset-top="200">
//....
</div>
用法二:通过JavaScript
$('#myAffix').affix({
offset:{
top: 100,
bottom:function(){
return (this.bottom = $('.bs-footer').outHeight(true));
}
}
})