Warning: file_get_contents(/data/phpspider/zhask/data//catemap/7/css/32.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
与FF和IE相比,jQuery在Chrome中返回错误的元素位置_Jquery_Css_Google Chrome_Scroll_Height - Fatal编程技术网

与FF和IE相比,jQuery在Chrome中返回错误的元素位置

与FF和IE相比,jQuery在Chrome中返回错误的元素位置,jquery,css,google-chrome,scroll,height,Jquery,Css,Google Chrome,Scroll,Height,我正在编写一个函数来测试滚动条的位置和我存储在数组中的预定义元素的位置。页面上可以有任意数量的这种元素类型,这就是为什么我使用for循环来测试滚动条的位置 这段代码在Firefox中运行良好,但出于某种原因,jQuery在Chrome中为my.post info($pi)的每个项目返回了完全不同的位置,甚至错误地获取了$(document).height。这是我的javascript还是css的问题?我将假设我的JS,因为我已经测试了css中大多数元素的position:relative 下面是

我正在编写一个函数来测试滚动条的位置和我存储在数组中的预定义元素的位置。页面上可以有任意数量的这种元素类型,这就是为什么我使用for循环来测试滚动条的位置

这段代码在Firefox中运行良好,但出于某种原因,jQuery在Chrome中为my.post info($pi)的每个项目返回了完全不同的位置,甚至错误地获取了$(document).height。这是我的javascript还是css的问题?我将假设我的JS,因为我已经测试了css中大多数元素的position:relative

下面是我正在运行的jQuery:

(function(){
var i,
st,
length,
arrPos = []

  $wn = $(window);
  $pi = $('.post-info');

  $pi.each(function(){
    arrPos.push($(this).offset().top - 80); // offset -80 so new item sticks quicker.
  });
  height = $(document).height();
  arrPos.push(height); // add bottom position of document to array for last item.

  length = arrPos.length;           
  $wn.scroll(function(){ //Scroll Event Listener
    st = $wn.scrollTop();
    for(i=0; i<=length; i++){
       // i = index, n = next
       n = i+1;
       if(st > arrPos[i] && st < arrPos[n]) _stick(i);
    }
});
(函数(){
var i,
圣,
长度,
arrPos=[]
$wn=$(窗口);
$pi=$('.post-info');
$pi.each(函数(){
arrPos.push($(this.offset().top-80);//offset-80,这样新项目粘起来更快。
});
高度=$(文档).height();
arrPos.push(高度);//将文档的底部位置添加到最后一项的数组中。
长度=arrPos.length;
$wn.scroll(函数(){//scroll事件侦听器
st=$wn.scrollTop();
对于(i=0;i arrPos[i]和&st

非常感谢。

谷歌浏览器在$(文档)后设置高度和宽度。准备好了吗 如果您有任何图像,那么此时您的页面尺寸将不正确。请尝试先预加载图像,完成后调用函数。
希望能有所帮助:)

谢谢你的建议,但我发现问题在于我的图像中没有一幅设置了特定的高度——我补充说,现在Chrome承认了它们的存在,一切都很好!谢谢