[英]jQuery code working in Safari and Chrome but not Firefox
我有一个网站,其中包含大量推文,并且当您向下滚动右栏时,您也会看到该推文的统计信息。 (可在http://www.grapevinegame.com上查看其运行情况。单击“记忆”,然后单击“跳过”以进入列表页面。可在Safari和Chrome中使用。)
我正在使用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);
}
});
});
感谢任何帮助或建议!
更新!
似乎$("body").scrollTop()
总是返回0,我认为这是问题所在。
但是,当我尝试$(“ html”)。scrollTop()时,似乎返回了正确的scrollTop。
尝试将scrollPosition行更改为此:
scrollPosition = $("html").scrollTop(),
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.