如何增加向上滚动的数量

时间:2019-05-10 11:19:34

标签: javascript reactjs react-native ecmascript-6

我必须在每个滚动上增加计数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;
         });

2 个答案:

答案 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>
相关问题