关于javascript:关于居中问题

对于居中

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 })
   });
}

评论

发表回复

您的邮箱地址不会被公开。 必填项已用 * 标注

这个站点使用 Akismet 来减少垃圾评论。了解你的评论数据如何被处理