[英]scroll eevent and scrollTop not working in firefox
I want to get the scrollTop value on scroll event. 我想在滚动事件上获取scrollTop值。
Works good on Chrome but not on firefox. 在Chrome上效果很好,但在Firefox上效果不好。 What is the way to get this, crossbrowser/vanilla JS?
跨浏览器/香草JS的获取方式是什么?
var i = 0;
window.onscroll = function () {
var scrollTop = document.body.scrollTop;
console.log(scrollTop,i); // always 0, (i works as expected)
i++;
};
Ps- I don't think a setTimeout is a good practise/solution for this... ps-我认为setTimeout并不是解决这个问题的好方法/解决方案...
var i = 0;
var doc = document;
window.onscroll = function () {
var scrollTop = doc.documentElement.scrollTop || doc.body.scrollTop;
console.log(scrollTop,i);
i++;
};
https://developer.mozilla.org/en-US/docs/Web/API/document.documentElement https://developer.mozilla.org/en-US/docs/Web/API/document.documentElement
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.