当用户在iScroll4中滚动时,我想调用一些操作。也取决于滚动的位置和速度。
在哪里,怎样才能最好地实现这一目标?
对于addListener,我没有运气,因为它对准时发生的事件作出反应。触动,触地启动。我需要的是知道div何时滚动..。
有什么想法吗?
发布于 2013-06-06 09:36:26
有许多回调函数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。但是我认为你可以用可用的值来计算速度。
发布于 2016-01-27 02:53:42
滚动事件仅在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
})https://stackoverflow.com/questions/16957013
复制相似问题