三鸿蒙轮播图和轮播布局综合

noutsider
发布于 2021-1-18 20:42
浏览
0收藏

需读者要注意的点 已经在代码中标记

data数据模型驱动:

export default {
    data: {
        //定义菜单项
        menus:[{"text":"首页","img1":"./common/shoyyeu.png","img2":"./common/shouyes.png"},
               {"text":"资讯","img1":"./common/zixunu.png","img2":"./common/zixuns.png"},
               {"text":"分类","img1":"./common/fenleiu.png","img2":"./common/fenleis.png"},
               {"text":"我的","img1":"./common/wodeu.png","img2":"./common/wodes.png"}],
                //定义一个下标
                 cinidex:0
    },
    changecontent(index){
        //赋值
        this.cinidex=index;
        //改变轮播图的具哪一项和轮播图的index
        this.$element("sw").swipeTo({index:index})
    }

}

 

视图层渲染样式:

<div class="first">
    <!--轮播布局start-->
 <swiper class="swipview" id="sw" index="0">   <!--通过id取到页面上的元素-->
     <div class="box one">                      <!--微信小程序中此处是current而非index-->
         <!--轮播图start-->
            <swiper class="sswiper" autoplay="true" duration="3000" indicator="true" >
                <div class="view1">
                    <text txt2> 第一幅轮播图 </text>
                </div>
                <div class="view2">
                        <text txt2> 第二幅轮播图 </text>
                </div>
                <div class="view3">
                        <text txt2> 第三幅轮播图 </text>
                </div>
                <div class="view4">
                        <text txt2> 第四幅轮播图 </text>
                </div>
            </swiper>
         <!--轮播图end-->
     </div>
     <div class="box two">
         <text class="text1">第二幅</text>
     </div>
     <div class="box three">
         <text class="text1">第三幅</text>
     </div>
     <div class="box four">
         <text class="text1">第四幅</text>
     </div>
 </swiper>
    <!--轮播布局end-->
    <!--底部菜单栏鸿蒙必修嵌套在父容器中start-->
    <div class="bottomview">
        <block for="{{menus}}">
            <div class="content" onclick="changecontent({{$idx}})">
                <div class="imges">
                    <image src="{{cinidex==$idx?$item.img1:$item.img2}}">
                    </image>
                </div>
                <div class="text">
                    <text class="{{cinidex==$idx?'a':'b'}}">
                        {{$item.text}}
                    </text>
                </div>
            </div>
        </block>
    </div>
    <!--底部菜单栏鸿蒙必修嵌套在父容器中end-->
</div>

 

css属性设置

.first{
    width: 100%;
    height: 1200px;
    background-color: powderblue;
}
.bottomview{
    width: 100%;
    height: 200px;
    /**border-top:3px solid red;**/
    position: fixed;
    bottom: 0px;
    left: 0px;
    background-color: white;
    display: flex;
    justify-content: space-around ;

}
.content{
    width: 22%;
    height: 90%;
    /**border:1px solid black;**/
    display: flex;
    flex-direction: column;
    justify-content: center;
    align-items: center;
}
.imges{
    width: 40%;
    height: 40%;
    /*8border:2px solid blue;**/

}
.text{
    width: 80%;
    height: 40%;
    /**border:2px solid green ;**/
    display: flex;
    justify-content: center;

}
.a{
    color: red;
    font-size: 35px;
    font-weight: bold;
}
.b{
    font-size: 35px;
    color: grey;
    font-weight: bold;
}
.box{
    width: 100%;
    height: 90%;
}
.one{
background-color: skyblue;
    display: flex;

}
.sswiper{
    width: 100%;
    height: 500px;
}
.view1{
    width: 100%;
    height: 100%;
    background-color: darkorange;
    display: flex;
    align-items: center;
    justify-content: center;
}
.view2{
    width: 100%;
    height: 100%;
    background-color: deepskyblue;
    display: flex;
    align-items: center;
    justify-content: center;
}
.view3{
    width: 100%;
    height: 100%;
    background-color: green;
    display: flex;
    align-items: center;
    justify-content: center;
}
.view4{
    width: 100%;
    height: 100%;
    background-color: yellow;
    display: flex;
    align-items: center;
    justify-content: center;
}
.txt2{
 font-size: 150px;
    font-weight: bold;
}
.two{
    background-color: cornflowerblue;
    display: flex;
    justify-content: center;
    align-items: center;
}
.three{
    background-color: beige;
    display: flex;
    justify-content: center;
    align-items: center;
}
.four{
    background-color: darkorange;
    display: flex;
    justify-content: center;
    align-items: center;
}
.text1{
    font-family: sans-serif;
    font-weight: bold;
    font-size: 40px;
}

 

效果图如下:三鸿蒙轮播图和轮播布局综合-鸿蒙开发者社区

 

三鸿蒙轮播图和轮播布局综合-鸿蒙开发者社区

已于2021-1-26 13:05:01修改
6
收藏
回复
举报
1条回复
按时间正序
/
按时间倒序
lingyuli
lingyuli

可以的,代码和展示效果都挺全面的

1
回复
2021-1-19 09:50:38
回复
    相关推荐