Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/399.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript IScroll4,当div滚动时如何调用函数?_Javascript_Scroll_Hook_Iscroll4 - Fatal编程技术网

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

Javascript IScroll4,当div滚动时如何调用函数?,javascript,scroll,hook,iscroll4,Javascript,Scroll,Hook,Iscroll4,当用户在iScroll4中滚动时,我想调用一些操作。还取决于滚动的位置和速度 在哪里以及如何最好地实现这一点 有了addListener,我就不走运了,因为它会对实时事件做出反应,例如Touchmove、touchstart。我需要的是知道div何时滚动 有什么想法吗?有很多回调函数iScroll。您可以将这些用于您的目的 一个关于这些的小解释 scroller = new iScroll('ID', { onRefresh : function(){ /* iScroll prov

当用户在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. */
  }
});
我刚才给了你一个关于一些回调函数的小解释。但是还有一些其他的存在,例如
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
位置。从这些你可以直接得到滚动条的位置。但是要获得滚动条的速度,必须使用
物理
;)。它返回
时间戳
滚动条位置
。我想你可以用这些值来计算速度。很抱歉,目前我无法分析这些值,以准确说明如何获得
速度
。但是我认为您可以使用可用的值来计算速度。

滚动事件仅在iScroll probe edition(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         
    })

太好了!有什么建议我可以得到的位置和滚动层的滚动速度?谢谢你尝试这个。职位是最需要的部分。我能计算的速度:)非常感谢。