微信 小程序组件 滑动导航和获取元素实际高度

 

 

<view>
<scroll-view scroll-x scroll-with-animation scroll-left="{{menuIndex}}" style="height: 100px; width:100%;">
<view id='#haha' class='all' style='width:{{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);
})

},

转载于:https://www.cnblogs.com/dianzan/p/8308460.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值