繁体   English   中英

IScroll4,如何在div滚动时调用函数?

[英]IScroll4, how to call functions when the div is scrolling?

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

在哪里以及如何最好地解决这个问题?

使用addListener我没有运气,因为它会对准时事件作出反应,例如。 Touchmove,touchstart。 我需要的是知道div何时滚动..

有任何想法吗?

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 但我认为您可以使用可用值来计算速度。

scroll事件仅在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         
    })

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM