更新时间:2019-10-18 01:20:04
请注意:该插件仅支持移动端,不支持PC端
参数:
new Touch({ contEl:document.getElementById("shadowBox"), //背景灰色浮层,必选参数 shadowEl:document.getElementById("contBox"), //内容块,必选参数 top:0.1, //内容块停留的最高处 (取值范围:0.1-1,默认0.1),可选参数 bottom:0.9, //内容块停留的最低处 (取值范围:0.1-1,默认0.9),可选参数 opacity:0.5, //背景灰色浮层的最高透明值 (取值范围:0.1-1,默认0.5),可选参数 duration:0.3 //松手时候下滑或上滑动画的持续时间 (单位:秒,默认0.3),可选参数 });
contBox里面的内容改成这样:
<div id="contBox"> <div style="height: 50px; position: absolute; top: 0; left: 0;">固定的内容</div> <div style=" position: absolute; top: 50px; bottom: 0; left: 0; width: 100%; overflow: auto;"> <!--这里放任何想放的内容--> <div style="height: 150px;background: red;">上滑这个红色块试试</div> <div style="height: 150px;background: orange;"></div> <div style="height: 150px;background: yellow;"></div> <div style="height: 150px;background: green;"></div> <div style="height: 150px;background: blue;"></div> <div style="height: 150px;background: purple;"></div> </div> </div>
我在touchend中加了个判断
touchend: function(e) { var _this = this; if (this.state == "scroll") { return; } this.y = this.direction == "toBottom" ? this.bottom : this.top; this.height = this.h - this.y; this.opacity = this.direction == "toBottom" ? 0 : this.opacityMax; this.setDom("end"); // 加了个判断 if (!this.direction) { this.direction = "toBottom" this.contEl.style.overflow = "auto"; } else if (this.direction == "toBottom") { this.direction = "toTop" } else { this.direction = "toBottom" this.contEl.style.overflow = "auto"; } // end this.ifTouch = false; },