html的锚链接位置偏差解决

使用锚链接,链接到位置有时有位置偏差

<script type="text/javascript">$(function(){

    var url = window.location.toString();

    var id = url.split("#")[1];

   if(id){

      var t = $("#"+id).offset().top-100;//位置偏差可调

      $(window).scrollTop(t);

   }

});

</script>

posted @ 2018-01-10 17:43  小梦19  阅读(441)  评论(0编辑  收藏  举报