#2020征文-手机#鸿蒙js开发三: 自定义菜单和轮播布局和轮播图

六合李欣
发布于 2021-1-14 16:49
浏览
0收藏

1.  效果图:

#2020征文-手机#鸿蒙js开发三: 自定义菜单和轮播布局和轮播图-鸿蒙开发者社区

2. 页面hml视图构建 :

<div  class="firstview">
    <!-- 轮播布局 start -->
    <swiper class="swiperview"  id="sw"  index="0">
        <div  class="box one">
            <!--轮播图  start -->
            <swiper class="swtxt" autoplay="true"   duration="5000"  interval="3000" indicator="true" loop="true"  index="0">
               <div  class="switem one1">
                    <text class="onet1">第一幅轮播图</text>
               </div>
                <div  class="switem one2">
                    <text class="onet1">第二幅轮播图</text>
                </div>
                <div  class="switem one3">
                    <text class="onet1">第三幅轮播图</text>
                </div>
            </swiper>
            <!--轮播图  end -->
       </div>
        <div class="box two">
            <text class="txt1">第二幅</text>
        </div>
        <div class="box three">
            <text class="txt1">第三幅</text>
        </div>
        <div class="box four">
            <text class="txt1">第四幅</text>
        </div>
    </swiper>
    <!-- 轮播布局 end -->

    <!--底部菜单栏 鸿蒙必须嵌套到父的视图容器start-->
    <div  class="bottommenuview">
        <block  for="{{menus}}">
            <div  class="cellmenu"  onclick="changemenu({{$idx}})">
                <div class="imgview">
                    <image class="cimg"
                            src="{{cindex==$idx?$item.img1:$item.img2}}">
                    </image>
                </div>
                <div  class="txtview">
                  <text class="{{cindex==$idx?'a':'b'}}">{{$item.text}}</text>
                </div>
            </div>
        </block>
    </div>
    <!--底部菜单栏 鸿蒙必须嵌套到父的视图容器end-->

</div>

2.样式文件

.firstview{
    width: 100%;
    height: 1200px;
    background-color: deepskyblue;
}

.bottommenuview{
    width: 100%;
    height: 160px;
    border-top:5px  solid   black;
    position: fixed;
    bottom: 0px;
    left: 0px;
    background-color: powderblue;
    display: flex;
    justify-content: space-around;
    
}
.cellmenu{
    width: 22%;
    height: 90%;
    /**border: 1px  solid  red;**/
    display: flex;
    flex-direction: column;
    justify-content: center;
    align-items: center;
}
.imgview{
    width: 80%;
    height: 50%;
   /** border:2px solid  black;**/
    display: flex;
    justify-content: center;
    align-items: flex-end;

}
.txtview{
    width: 80%;
    height: 40%;
   /** border:2px solid  green;**/
    display: flex;
    justify-content: center;
    align-items: center;
}
.a{
    color: black;
    font-size: 25px;
    font-weight: bold;

}
.b{
    color: green;
    font-size: 25px;
    font-weight: bold;
}
.cimg{
    width: 40px;
    height: 40px;
}
.swiperview{
    width: 100%;
    height: 100%;
}
.box{
    width: 100%;
    height: 100%;

}
.one{
    background-color: palegreen;
    
}
.two{
    
    background-color: deepskyblue;
    
}
.three{
    
    background-color: cornflowerblue;
    
}
.four{
    
    background-color: aqua;
    
}
.txt1{
    font-family:sans-serif;
    font-size: 60px;
    
}
.swtxt{
    width: 800px;
    height: 300px;

}
.switem{
    width: 100%;
    height: 100%;
    display: flex;
    justify-content: center;
    align-items: center;
}
.one1{
    background-color: aqua;
}
.one2{
    background-color: cornflowerblue;
}
.one3{
    background-color: deepskyblue;
}
.onet1{
    font-size: 60px;
    color: snow;
    font-weight: bold;
}

3.js业务逻辑

export default {
    data: {
        title: 'World',

        //定义菜单项
        menus:[{"text":"首页","img1":"./common/ones.png","img2":"./common/oneu.png"},
               {"text":"分类","img1":"./common/cs.png","img2":"./common/cu.png"},
               {"text":"内容","img1":"./common/cons.png","img2":"./common/conu.png"},
               {"text":"我的","img1":"./common/mys.png","img2":"./common/myu.png"}],

        //定义一个下标
        cindex:0

    },
    changemenu(index)
    {
        console.log("当前的值为:"+index);
        //赋值
        this.cindex=index;

        //改变轮播图的具体哪项  和轮播图的index
        this.$element("sw").swipeTo({index:index});

    }

}

4.工程目录结构图:

#2020征文-手机#鸿蒙js开发三: 自定义菜单和轮播布局和轮播图-鸿蒙开发者社区

分类
标签
已于2021-1-20 16:11:08修改
2
收藏
回复
举报
回复
    相关推荐