微信小程序页面制作练习——制作一个九宫格导航图

要求:

代码实现:

先将所需要的资源图片存入我的image文件里面

模拟练习供参考,不建议这样存入image里,因为本地图片占内存太大,不能预览。

一、list.wxml里面搭建框架代码:

<!--pages/list/list.wxml-->
<navigation-bar title="Weixin" back="{{false}}" color="red"></navigation-bar>
<scroll-view class="scrollarea" scroll-y type="list">
<swiper interval="2000" autoplay="true" indicator-dots="true" indicator-color="black" indicator-active-color="gray">
    <swiper-item><image src="../../images/swiper01.jpg" mode="" style="width: 100%;height: 100%;"/></swiper-item>
    <swiper-item><image src="../../images/swiper02.jpg" mode=""  style="width: 100%;height: 100%;"/></swiper-item>
</swiper>
<view class="grids">
<view class="border">
    <image src="../../images/shi.png" mode="" style="width:80rpx;height:80rpx;"/>
    <text>美食</text>
</view>
<view class="border">
    <image src="../../images/xiu.png" mode="" style="width:80rpx;height:80rpx;"/>
    <text>装修</text>
</view>
<view class="border">
    <image src="../../images/yu.png" mode="" style="width:80rpx;height:80rpx;"/>
    <text>洗浴</text>
</view>
<view class="border">
    <image src="../../images/che.png" mode="" style="width:80rpx;height:80rpx;"/>
    <text>汽车</text>
</view>
<view class="border">
    <image src="../../images/chang.png" mode="" style="width:80rpx;height:80rpx;"/>
    <text>唱歌</text>
</view>
<view class="border">
    <image src="../../images/fang.png" mode="" style="width:80rpx;height:80rpx;"/>
    <text>住宿</text>
</view>
<view class="border">
    <image src="../../images/xue.png" mode="" style="width:80rpx;height:80rpx;"/>
    <text>学习</text>
</view>
<view class="border">
    <image src="../../images/gong.png" mode="" style="width:80rpx;height:80rpx;"/>
    <text>工作</text>
</view>
<view class="border">
    <image src="../../images/hun.png" mode="" style="width:80rpx;height:80rpx;"/>
    <text>结婚</text>
</view>
</view>
</scroll-view>

二、list.wxss搭建样式代码:

/* pages/list/list.wxss */
.grids{
    display: flex;
    flex-wrap: wrap;
    margin-left: 5rpx;
}
.border{
    display: flex;
    border: 1px solid rgb(167, 165, 165);
    width: 246rpx; /*750÷3 =250*/
    height: 250rpx;
    flex-direction: column;
    justify-content: center;
    align-items: center;
}
.border text{
    font-size: smaller;
    color: gray;
    margin-top: 10rpx;
}
.border:nth-child(1){
    border: none;
}
.border:nth-child(2){
    border-right: none;
    border-bottom: none;
    border-top: none;
}
.border:nth-child(3){
    border-right: none;
    border-bottom: none;
    border-top: none;
}
.border:nth-child(4){
    border-right: none;
    border-bottom: none;
    border-left:none ;
}
.border:nth-child(5){
    border-right: none;
    border-bottom: none;
}
.border:nth-child(6){
    border-right: none;
    border-bottom: none;
}
.border:nth-child(7){
    border-right: none;
    border-left: none;
}
.border:nth-child(8){
    border-right: none;
}
.border:nth-child(9){
    border-right: none;
}

三、运行结果如图所示:

  • 1
    点赞
  • 6
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论
好的,以下是一个微信小程序界面跳转九宫格的实现代码: WXML: ``` <view class="grid-container"> <view class="grid-item" hover-class="hover" bindtap="goScanQRCode"> <image src="/images/scan_qrcode.png"></image> <text>Scan QR Code</text> </view> <view class="grid-item" hover-class="hover" bindtap="goContacts"> <image src="/images/contacts.png"></image> <text>Contacts</text> </view> <view class="grid-item" hover-class="hover" bindtap="goDiscover"> <image src="/images/discover.png"></image> <text>Discover</text> </view> <view class="grid-item" hover-class="hover" bindtap="goMe"> <image src="/images/me.png"></image> <text>Me</text> </view> </view> ``` CSS: ``` .grid-container { display: grid; grid-template-columns: repeat(3, 1fr); grid-gap: 10px; } .grid-item { text-align: center; cursor: pointer; } .grid-item image { width: 80px; height: 80px; } .grid-item text { margin-top: 10px; font-size: 14px; } ``` JS: ``` Page({ goScanQRCode: function () { wx.scanCode({ success(res) { console.log(res) } }) }, goContacts: function () { wx.navigateTo({ url: '/pages/contacts/contacts' }) }, goDiscover: function () { wx.navigateTo({ url: '/pages/discover/discover' }) }, goMe: function () { wx.navigateTo({ url: '/pages/me/me' }) } }) ``` 上面的代码实现了一个九宫格,每个格子都有一个标和一个标题,可以通过点击实现微信小程序界面的跳转。其中,`wx.scanCode()`可以调用微信的扫一扫功能,`wx.navigateTo()`可以跳转到指定的页面,以此类推。需要注意的是,跳转页面的路径需要在小程序的 app.json 中注册。

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

想想aw

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值