2010-04-17 93 views
0

我有一个网站,有很长的鸣叫列表,当你向下滚动右边的列跟着你,显示鸣叫的统计。 (请参阅http://www.grapevinegame.com,点击“记忆”,然后点击“跳过”进入列表页面,在Safari和Chrome中运行)。jQuery代码工作在Safari和Chrome,但不是Firefox

我正在使用jQuery来更新右列的顶部边距,当我向下滚动时增加它。它似乎在基于webkit的浏览器中工作正常,但不会在Firefox中生效。下面是代码,右边的列元素是id =“distance”的div。

// Listen for scroll function 
      $(window).scroll(function() { 

        // Calculating the position of the scrollbar 
        var doc = $("body"), 
        scrollPosition = $("body").scrollTop(), 
        pageSize = $("body").height(), 
        windowSize = $(window).height(), 
        fullScroll = (pageSize) - windowSize; 
        percentageScrolled = (scrollPosition/fullScroll); 

        var entries = $("#whispers-list > li").length; 

        // Set position of distance counter 
        $('div#distance').css('margin-top', ($("#whispers-list").height()+$("#latest-whisper").height()+33)*percentageScrolled); 

        // Update distance counter 
         $('#distance-travelled').text(Math.round(distanceTravelled*(1-percentageScrolled)));    
         $('#whispers-list li').each(function(index) { 

           //highlight adjacent whispers        
           if ($('#whispers-list li:nth-child('+(index+1)+')').offset().top >= $('#distance').offset().top && $('#whispers-list li:nth-child('+(index+1)+')').offset().top <= $('#distance').offset().top + $('#distance').height()) { 
            // alert("yup"); 
            $('#whispers-list li:nth-child('+(index+1)+') ul').fadeTo(1, 1); 
           } else { 
            $('#whispers-list li:nth-child('+(index+1)+') ul').fadeTo(1, 0.5); 
           } 
           });    

        }); 

感谢任何帮助或建议!

回答

1

更新!

看来,$("body").scrollTop()总是返回0,我认为这是问题。

但是,当我尝试$(“html”)。scrollTop()它似乎是返回正确的scrollTop。

尝试改变的scrollPosition行这样的:

scrollPosition = $("html").scrollTop(), 
+0

感谢,尝试都没有,但现在似乎没有任何区别 – 2010-04-17 01:31:08

+0

偏移值只有真正使用反正突出相邻里的,和只看起来与() – 2010-04-17 01:36:27

+0

Gotcha,好吧,我看了一些后,我认为问题是使用$(“body”)。scrollTop()...尝试更改为$(“html”)。scrollTop (),这似乎在FF中为我返回正确的值。 – 2010-04-17 01:51:06

相关问题