zoukankan      html  css  js  c++  java
  • 微信 小程序组件 滑动导航和获取元素实际高度

    <view>
    <scroll-view scroll-x scroll-with-animation scroll-left="{{menuIndex}}" style="height: 100px; 100%;">
    <view id='#haha' class='all' style='{{menuWidth}}px;'>
    <block wx:key="lists" wx:for="{{lists}}">
    <view id="a{{index}}" bindtap='jumpIndex' class='menu' data-menuindex='{{index}}'>{{item.list}}</view>
    </block>
    </view>
    </scroll-view>
    </view>
     
     
    data: {
    // 初始化滑动条数据
    menuIndex:0,
    // 每个菜单的宽度
    onlyWidth: 70,
    // 右侧的margin
    marginWidth:10,
    // 菜单总长
    menuWidth:0,
     
    lists:[
    { list: 'a1' },
    { list: 'a2' },
    { list: 'a3' },
    { list: 'a4' },
    { list: 'a5' },
    { list: 'a6' },
    { list: 'a7' }
    ],
    },

    jumpIndex:function(e){
    var menuIndex = (e.currentTarget.dataset.menuindex-1)*80;
    this.setData(
    {menuIndex:menuIndex}
    )
    },

    /**
    * 生命周期函数--监听页面加载
    */
    onLoad: function (options) {
     

    let that=this;
    let lists = this.data.lists;
    let onlyWidth=this.data.onlyWidth;
    let marginWidth=this.data.marginWidth;
    let menuWidth = lists.length * (onlyWidth + marginWidth) - marginWidth;
    that.setData({
    menuWidth: menuWidth
    })
    // 获取用户高度
    let query = wx.createSelectorQuery();
    query.select('#a0').boundingClientRect()
    query.exec(function (res) {
    console.log(res);
    })

    },
  • 相关阅读:
    JDOJ 2197: 校门外的树
    简单线段树知识点详解
    求GCD(最大公约数)的两种方式
    USACO Buying Feed, II
    USACO Dueling GPS's
    USACO Milking Cows
    NOIP 2014 比例简化
    USACO Clumsy Cows
    JDOJ 1140: 完数
    NOIP 2008 火柴棒等式
  • 原文地址:https://www.cnblogs.com/dianzan/p/8308460.html
Copyright © 2011-2022 走看看