微信小程序组件滑动导航和获取元素实际高度 - 新闻资讯 - 云南小程序开发|云南软件开发|云南网站建设-昆明葵宇信息科技有限公司

159-8711-8523

云南网建设/小程序开发/软件开发

知识

不管是网站,软件还是小程序,都要直接或间接能为您产生价值,我们在追求其视觉表现的同时,更侧重于功能的便捷,营销的便利,运营的高效,让网站成为营销工具,让软件能切实提升企业内部管理水平和效率。优秀的程序为后期升级提供便捷的支持!

您当前位置>首页 » 新闻资讯 » 小程序相关 >

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

发表时间:2021-3-31

发布人:葵宇科技

浏览次数:60


  1. <view>
  2. <scroll-view scroll-x scroll-with-animation scroll-left="{{menuIndex}}" style="height: 100px; width:100%;">
  3. <view id='#haha' class='all' style='width:{{menuWidth}}px;'>
  4. <block wx:key="lists" wx:for="{{lists}}">
  5. <view id="a{{index}}" bindtap='jumpIndex' class='menu' data-menuindex='{{index}}'>{{item.list}}</view>
  6. </block>
  7. </view>
  8. </scroll-view>
  9. </view>
  1. data: {
  2. // 初始化滑动条数据
  3. menuIndex:0,
  4. // 每个菜单的宽度
  5. onlyWidth: 70,
  6. // 右侧的margin
  7. marginWidth:10,
  8. // 菜单总长
  9. menuWidth:0,
  1. lists:[
  2. { list: 'a1' },
  3. { list: 'a2' },
  4. { list: 'a3' },
  5. { list: 'a4' },
  6. { list: 'a5' },
  7. { list: 'a6' },
  8. { list: 'a7' }
  9. ],
  10. },
  11. jumpIndex:function(e){
  12. var menuIndex = (e.currentTarget.dataset.menuindex-1)*80;
  13. this.setData(
  14. {menuIndex:menuIndex}
  15. )
  16. },
  1. /**
  2. * 生命周期函数--监听页面加载
  3. */
  4. onLoad: function (options) {
  5. let that=this;
  6. let lists = this.data.lists;
  7. let onlyWidth=this.data.onlyWidth;
  8. let marginWidth=this.data.marginWidth;
  9. let menuWidth = lists.length * (onlyWidth + marginWidth) - marginWidth;
  10. that.setData({
  11. menuWidth: menuWidth
  12. })
  13. // 获取用户高度
  14. let query = wx.createSelectorQuery();
  15. query.select('#a0').boundingClientRect()
  16. query.exec(function (res) {
  17. console.log(res);
  18. })
  19. },

相关案例查看更多