我必须在每个滚动上增加计数1,例如:
let scrollCount = 0;
//initially it would be 0 and after every scroll up it should increase 1,
scrollCount++;
react-native每次滚动时递增计数1的功能是什么。
//下面的js代码我知道..但是对于react-native感到困惑。
var scrollCount = 0;
window.addEventListener('mousewheel', function(e){
if(e.wheelDelta<=0 && scrollCount<5){
scrollCount++;
}
else if(e.wheelDelta>0 && scrollCount>1){
scrollCount--;
}
document.querySelector('.number').innerHTML = scrollCount;
});
答案 0 :(得分:1)
object.onscroll = function(){
//myScript
};
每次滚动都运行您的脚本
或添加事件监听器:
object.addEventListener("scroll", myScript);
它变成这样:
var scrollCount = 0;
//object is your document. or any DOM element you would like to add
object.onscroll = function(){
scrollCount++;
};
答案 1 :(得分:0)
您将onScroll
回调添加到可滚动组件。
例如,如果您有ScrollView
,则可以这样做:
<ScrollView
onScroll={this.handleScroll}
>
<ComponentsWithinYourScrollView />
</ScrollView>
取决于您定义为滚动的内容,您可能希望仅在用户启动的每个滚动操作上增加,然后才可能要执行以下操作:
<ScrollView
onScrollBeginDrag={this.handleScrollStart}
>
<ComponentsWithinYourScrollView />
</ScrollView>