标签:AlloyTouch

共 1 篇相关文章

IT 累计浏览 2,975

AlloyTouch实现下拉刷新

在手机QQ中客户端虽已提供拖动 webview 的下拉刷新,但面对统一 iOS 与安卓体验、自定义下拉动画、与 web 内背景或 Dom 元素联动交互等场景时便无能为力,此时需要 web 自身具备下拉刷新能力,AlloyTouch 恰好擅长处理这类需求。

页面骨架上 pullRefresh 位于 AlloyTouch header 之下,层级为 header zIndex > pullRefresh zIndex > wrapper 和 scroller。下拉动画通过 JS 切换 arrow_up class、配合 CSS transition 实现箭头旋转与 wording 由 "Pull to refresh" 变为 "Release to refresh";loading 动画则用 SVG 的 12 个 rect 通过 indefinite animate 并递增 begin 时间来实现。核心逻辑是给 scroller 和 pull_refresh 注入 transform,用 AlloyTouch 的 change 回调让 pull_refresh.translateY 跟随 scroller,在 touchMove 中当下拉超过 70px 切换箭头状态,touchEnd 中则运动到 60px 显示 loading 并发起模拟请求,此时 return false 很重要,可阻止内部回弹与惯性运动;请求完成后插入新数据、复位箭头并 at.to(initialVaule),同时因内容增高需相应调小 min 值。