-->

IScroll4,如何调用函数时的股利正在滚动?(IScroll4, how to call fun

2019-10-18 05:28发布

我想打电话给一些行动,当用户在iScroll4滚动。 此外根据上滚动的位置和速度。

在哪里以及如何最好勾实现这一目标?

addListener我没有运气,因为它反应对时间的事件,如。 Touchmove,touchstart。 我需要的是当DIV的滚动知道..

有任何想法吗?

Answer 1:

有很多回调函数的iScroll 。 您可以使用这些为您的目的。

那些小的解释。

scroller = new iScroll('ID', {
  onRefresh : function(){
    /* iScroll provided feature to refresh the scroller. This will help to refresh the scroller container when you dynamically add contents. */
  },
  onBeforeScrollStart : function(e){
    /* this is nothing but just when your mousedown event (This will be triggered each and every mousedown event). This is very useful when your parent container have scroller and your child container also have scroller. Assume this is your child scroller. What you can do is just get your parent scroller object (parentScroller) and disable it "parentScroller.disable()" */
  },
  onScrollStart : function(){
    /* now you start to move your mouse while holding mouse left button */
  },
  onBeforeScrollMove : function(){
    /* this where your scroller is start to move actually */
  },
  onScrollMove : function(){
    /* now your scroller is moving. If you need to do something, when your scroller is moving you can do those here */
  },
  onBeforeScrollEnd : function(){
    /* your scroller movement is about to stop */
  },
  onScrollEnd : function(){
    /* your scorller movement stoped. Will say you have disable your parent scroller. Now this is the good place to enable your parent scroller "parentScroller.enable()"*/
  },
  onDestroy : function(){
    /* you destroy your scroller. iScroll is provide a feature to remove the attached sctoller. */
  }
});

我只是给大家介绍一下一些回调函数小的解释。 但也有一些存在诸如onTouchEndonZoomStartonZoomonZoomEnd 。 如果需要,您可以尝试的。

我希望这可以帮助你理清的问题。


最新获得的卷轴的位置和速度。

scroller = new iScroll('ID', {
  onScrollMove : function(e){
    /* this function return an object in which it has almost all the required stuffs. */
  }
});

供您参考console.log(e)和分析价值e了。 它返回大量的x & y位置。 从这些你可以直接得到滚动条位置。 但是,让你不得不使用滚动条的速度physics )。 它返回timestampscroller position 。 我想你可能到能够获得使用这些值的速度。 我此刻的抱歉,我不能分析这些价值说清楚,你怎么能得到的speed 。 但我认为你可以使用现有的数值计算的速度。



Answer 2:

该滚动事件可在iScroll探头版只(iscroll-probe.js)。 探头行为可以通过probeType选项来改变。

你可以在HTML和“iscroll-probe.js”:

    var myScroll = new IScroll('#container', { probeType: 3, mouseWheel: true });
        myScroll.on('scroll',function(){
        var top = parseInt(-this.y);// scrolltop value
        //do something with top         
    })


文章来源: IScroll4, how to call functions when the div is scrolling?