Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/tensorflow/5.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
不同的jquery offset()。chrome中刷新和加载之间的最大值_Jquery_Google Chrome_Offset - Fatal编程技术网

不同的jquery offset()。chrome中刷新和加载之间的最大值

不同的jquery offset()。chrome中刷新和加载之间的最大值,jquery,google-chrome,offset,Jquery,Google Chrome,Offset,我正在使用以下功能在我的页面上手动执行滚动定位链接: var hash = window.location.hash.substring(1); if (hash != ''){ var anchor = $('#' + hash + '_hash').offset().top - 50; $("html,body").animate({ scrollTop: anchor}, 1000) }; 代码正常工作,除了我得到的offset()值不同。在chrome中,top

我正在使用以下功能在我的页面上手动执行滚动定位链接:

var hash = window.location.hash.substring(1);
if (hash != ''){
      var anchor = $('#' + hash + '_hash').offset().top - 50;
      $("html,body").animate({ scrollTop: anchor}, 1000)
};
代码正常工作,除了我得到的
offset()值不同。在chrome中,top
在刷新和实际页面加载之间始终保持40px。在刷新时,我得到正确的值,在页面加载时,通过键入url或在新选项卡中打开,我得到相同的值减去40px

我已将此函数移动到
$(window.load)(函数(){…})我认为可能是一些缓存元素加载更改了值,但问题仍然存在


有人知道为什么会这样吗?我试图搜索类似的问题/答案,但尚未找到任何答案,因此如果这是重复的线索,我提前道歉。

同样的事情发生在我身上,真奇怪,我找不到解决方案