scrollTop()在Firefox中返回0,但不在Chrome中返回 [英] scrollTop() returns 0 in Firefox, but not in Chrome
问题描述
不知道是否有其他问题,如果是这样,我道歉,请不要释放猎犬。
使用html5 doctype并做一个快速控制台。注销我的滚动监听器,告诉我scrollTop()值的值。我基本上这样做,所以当我滚动一个点时,我改变了一个元素的不透明度。我正在使用MVS解决方案执行此操作,但我无法将其推送到外部站点,因此您可以查看。这里有一个简短的片段:
var opacity = 1;
var scrollTop = $('body')。scrollTop();
if(scrollTop> 200){
opacity = 0.1;
}
$('#element).css('opacity',opacity);
如果我在Chrome中滚动,我会得到一个console.log(scrollTop);显示我想要的内容(例如,我为每个滚动添加100个),并且在打开200个scrollTop后,我的不透明度消失。如果我在FF和IE7 +中滚动,var会返回每个滚动的0。如果我将$('body')。scrollTop()更改为$('document')。scrollTop();那么我得到一个空的滚动回报。
任何想法?
Thanks!
var scrollTop = $(document).scrollTop );
Not sure if there's another question regarding this, if so I apologize and please don't release the hounds.
Using the html5 doctype and doing a quick console.log off my scroll listener that tells me the value of scrollTop() value. I'm basically doing this so when I scroll past a point, I change the opacity of an element. I'm doing this using an MVS solution and I don't have the ability to push this to an external site so you can look. Here's a quick snippet:
var opacity = 1;
var scrollTop = $('body').scrollTop();
if (scrollTop > 200) {
opacity = 0.1;
}
$('#element).css('opacity', opacity);
If I scroll in Chrome, I get a console.log(scrollTop); displaying what I want (ie; 100 for each scroll I do) and my opacity disappears after I hit 200 scrollTop. If I scroll in FF and IE7+ the var returns "0" each scroll. If I change $('body').scrollTop() to $('document').scrollTop(); then I get a "null" return on scroll.
Any ideas? Thanks!
Try to use var scrollTop = $(document).scrollTop();
这篇关于scrollTop()在Firefox中返回0,但不在Chrome中返回的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!