找回密码
 立即注册

QQ登录

只需一步,快速开始

搜索本站精品资源

首页 教程频道 小程序开发 查看内容

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

作者:模板之家 2018-5-4 15:46 6009人关注

viewscroll-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={{li ... view scr ...

viewscroll-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="{{li ...

 
 
 

 


						
  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.  
  12. jumpIndex:function(e){
  13. var menuIndex = (e.currentTarget.dataset.menuindex-1)*80;
  14. this.setData(
  15. {menuIndex:menuIndex}
  16. )
  17. },
 

						
  1. /**
  2. * 生命周期函数--监听页面加载
  3. */
  4. onLoad: function (options) {
  5.  
  6.  
  7. let that=this;
  8. let lists = this.data.lists;
  9. let onlyWidth=this.data.onlyWidth;
  10. let marginWidth=this.data.marginWidth;
  11. let menuWidth = lists.length * (onlyWidth + marginWidth) - marginWidth;
  12. that.setData({
  13. menuWidth: menuWidth
  14. })
  15. // 获取用户高度
  16. let query = wx.createSelectorQuery();
  17. query.select('#a0').boundingClientRect()
  18. query.exec(function (res) {
  19. console.log(res);
  20. })
  21.  
  22. },


路过

雷人

握手

鲜花

鸡蛋
原作者: 模板之家 来自: 网络收集

全部回复(0)