关于居中

tab 点击元素居中(小程序)

// 获取客设备宽度
const clientWidth = dd.getSystemInfoSync().windowWidth / 2;
// 获取节点结合
const nodes = dd.createSelectorQuery().selectAll( '.tabs .item' );

handleTap(){
    const { index } = e.target.dataset;
    const { offsetLeft } = e.currentTarget;
    const PADDING = 96; // 盒子默认边距
    nodes.boundingClientRect().exec( rect => {
      const { width } = rect[0][ index ];
      const scrollLeft = offsetLeft - this.clientWidth / 2 + ( width / 2 ) - PADDING
      this.setData({ scrollLeft })
   });
}


心语花束
169 声望0 粉丝

web前端开发


« 上一篇
nvm
下一篇 »
nrm相关