1

当用户在 iScroll4 中滚动时,我想调用一些操作。还取决于滚动的位置和速度。

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

使用addListener我没有运气,因为它会对准时事件做出反应,例如。触摸移动,触摸启动。我需要知道 div 何时滚动..

有任何想法吗?

4

2 回答 2

3

有很多回调函数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. */
  }
});

我只是对一些回调函数给了你一个小的解释。但是还有一些存在,例如onTouchEnd, onZoomStart, onZoom, onZoomEnd。如果需要,您可以进行实验。

我希望这可以帮助您解决问题。


最新更新以获取滚动条的位置和速度。

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;)。它返回timestamp, scroller position。我认为您可能能够使用这些值来获得速度。很抱歉,我目前无法分析这些值以准确说明如何获得speed. 但我认为您可以使用可用值计算速度。

于 2013-06-06T09:36:26.600 回答
0

滚动事件仅在 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         
    })
于 2016-01-27T02:53:42.857 回答