<div id="fullpage"><div><div><div class="animated" data-show="bounceInLeft" data-hide="bounceOutLeft">AlloyTouch Introduction</div><div class="animated" data-delay="500" data-show="bounceInUp" data-hide="zoomOut"><img src="asset/alloytouch.png"></div><div class="animated" data-delay="1200" data-show="bounceIn" data-hide="bounceOut">By AlloyTeam</div></div></div><div><div><div class="animated" data-delay="100" data-show="flipInY" data-hide="flipOutY" >Powerful Features</div><div class="animated" data-delay="400" data-show="zoomIn" data-hide="zoomOut"><img src="asset/power.png"></div></div></div>......... </div>注意,上面只是部分HTML,而且我已经把一些和插件配置无关的HTML去掉了。下面一一进行分析:
new AlloyTouch.FullPage("#fullpage",{animationEnd:function () {},leavePage: function (index) {console.log("leave"+index)},beginToPage: function (index) {console.log("to"+index);pb.to(index / (this.length-1));}});
new AlloyTouch({touch: this.parent,target: this.parent,property: "translateY",min: (1 - this.length) * this.stepHeight,max: 0,step: this.stepHeight,inertia: false,bindSelf : true,touchEnd: function (evt, v, index) {var step_v = index * this.step * -1;var dx = v - step_v;if (v < this.min) {this.to(this.min);} else if (v > this.max) {this.to(this.max);} else if (Math.abs(dx) < 30) {this.to(step_v);}else if (dx > 0) {self.prev();} else {self.next();}return false;},animationEnd: function () {option.animationEnd.apply(this,arguments);self.moving = false;}});
这里其实是嵌套的滚动。滚动里面的会导致外面的也滚动?怎么解决?里面的滚动必须加上bindSelf并且阻止冒泡:
且看内部滚动的详细代码:
var scroller = document.querySelector("#scroller");Transform(scroller,true);new AlloyTouch({touch:"#demo0",target: scroller, property: "translateY", min:250-2000,max: 0 ,touchStart:function(evt){evt.stopPropagation();},touchMove:function(evt){evt.stopPropagation();},bindSelf:true})这样的话,嵌套的HTML里面的嵌套的AlloyTouch就不会向上冒泡了,也就是滚动里面的就不会触发外面的滚动。