zoukankan      html  css  js  c++  java
  • 微信小程序组件 滚动导航

    JS

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

    },
     
     
    //-----------------------------------------------------------------------------------------
    wxml
    <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>
     
    //-----------------------------------------------------------------------------------------
    .all{
    display: flex;
    flex-direction: row;
    overflow: hidden;
    }

    .all .menu:last-child{
    margin-right: 0;
    }
    .menu{
    70px;
    height:40px;
    background-color:rebeccapurple;
    border-radius: 3px;
    margin-right: 10px;

    }
    .hehe{
    200rpx;
    height: 100rpx;
    background-color:red;
    }
  • 相关阅读:
    sql Test
    使用Team Foundation Server进行源代码管理
    幸运的秘密
    使用Dotmsn扩展Joymsg聊天机器人,使其同时支持QQ.MSN
    发布.net项目开发工具新版
    C#.Net项目生成器(ibatis)使用说明
    敏捷开发,Agile Development
    单元测试基础篇VS2008
    iBATIS.NET
    IBatis.Net学习笔记系列
  • 原文地址:https://www.cnblogs.com/dianzan/p/7985225.html
Copyright © 2011-2022 走看看