scrollCenter.js 682 B

1
  1. export default Behavior({methods:{getRect(t,e=!1){return new Promise((r,s)=>{const o=wx.createSelectorQuery().in(this);(e?o.selectAll(t):o.select(t)).boundingClientRect(t=>{if(!t)return s("找不到元素");r(t)}).exec()})},queryScrollNode(t,e,r="width"){const s=t[e];this.getRect(".l-tabsscroll").then(o=>{const l=o[r];let c=t.slice(0,e).reduce((t,e)=>t+e[r],0);c+=(s[r]-l)/2,"width"===r?this.setData({transformX:c,transformY:0}):this.setData({transformX:0,transformY:c})})},queryMultipleNodes(){const{placement:t,currentIndex:e}=this.data;this.getRect(".l-tabs-item",!0).then(r=>{-1!==["top","bottom"].indexOf(t)?this.queryScrollNode(r,e):this.queryScrollNode(r,e,"height")})}}});