先上效果图

使用注意事项

1:注意在app.json中注册页面路径

2:如果要增加新的Item,可到js中对listService数组进行增加

3:listService参数[

title:分类标题

items:这个分类下的所有Item[

name:这个Item的名字

url:这个Item点击跳转路径

icon:图标

]

]

WXML代码


<view id='services' class='services'>
<view class="grid" wx:for="{{servers}}" wx:key="">
<view class='grid-title'>
<text>{{item.title}}</text>
</view>
<view class='grid-items'>
<block wx:for="{{item.items}}" wx:key="">
<view class='grid-item'>
<view wx:if="{{item.enabled}}" class='mask'>
<text>{{item.detail}}</text>
</view>
<view class='navigator' data-path='{{item.url}}' data-isBind='{{item.isBind}}' bindtap='bindNavigator' hover-class="none">
<view class='item-content'>
<view class="item-content-icon">
<image src="{{item.icon}}" mode="scaleToFill" />
</view>
<text class="weui-grid_label">{{item.name}}</text>
</view>
</view>
</view>
</block>
</view>
</view>
</view>

WXSS

page{
background:#eeecec;
}
.enable{
z-index: 99999;
background: #404040;
opacity: 0.8;
position: absolute;
width: 100;
bottom: 0px;
top: 0px;
left: 0px;
right: 0px;
display: flex;
justify-content: center;
align-items: center;
color: #ffffff;
}
.enable text{
color: #fafafa;
font-size: 18px;
font-weight: bold; } .grid {
background: #ffffff;
margin-bottom:10px;
}
.services{
background:#f5f5f5; }
.navigator{
padding:20px 10px;
}
.grid-items { position: relative;
overflow: hidden;
display: flex;
flex-direction: row;
flex-wrap: wrap; }
.grid-items::before{
content: " ";
position: absolute;
left: 0;
top: 0;
right: 0;
height: 1px;
border-top: 1px solid #d9d9d9;
}
.grid-items::after{
content: "";
position: absolute;
left: 0;
top: 0;
width: 1px;
bottom: 0;
border-left: 1px solid #d9d9d9;
color: #d9d9d9;
-webkit-transform-origin: 0 0;
transform-origin: 0 0;
-webkit-transform: scaleX(0.5);
transform: scaleX(0.5);
}
.grid-item{
position: relative;
float: left;
width: 33.33333333%;
box-sizing: border-box;
} .grid-item::before{
content: " ";
position: absolute;
right: 0;
top: 0;
width: 1px;
bottom: 0;
border-right: 1px solid #d9d9d9;
color: #d9d9d9;
-webkit-transform-origin: 100% 0;
transform-origin: 100% 0;
-webkit-transform: scaleX(0.5);
transform: scaleX(0.5);
}
.grid-item::after{
content: " ";
position: absolute;
left: 0;
bottom: 0;
right: 0;
height: 1px;
border-bottom: 1px solid #d9d9d9;
color: #d9d9d9;
-webkit-transform-origin: 0 100%;
transform-origin: 0 100%;
-webkit-transform: scaleY(0.5);
transform: scaleY(0.5);
}
.item-content{
position: relative; padding: 0px 0px;
width: 100%;
box-sizing: border-box;
}
.item-content-icon{
width: 32px;
height: 32px;
margin: 0 auto;
}
.item-content-icon image{
display: block;
width: 100%;
height: 100%;
}
.weui-grid_label {
display: block;
text-align: center;
font-weight: bold;
color: #707070;
font-size: 16px;
white-space: nowrap;
text-overflow: ellipsis;
overflow: hidden;
}
.grid-title{
display: block; font-weight: bold;
color: #707070;
font-size: 14px;
white-space: nowrap;
text-overflow: ellipsis;
overflow: hidden;
padding: 7px; }
.mask{
width: 100%;
height: 100%; position: absolute;
z-index: 999;
text-align: center;
background: rgba(0, 0, 0, 0.619);
color: #eee8e8;
line-height: 32px;
display: flex; }

最重要的JS


const app = getApp() Page({
data: {
servers:[]
}, onLoad: function () {
var listService = [
{
title: '社会',
items: [{
name: '捐助',
url: '/pages/TestPage/TestPage',
icon: '/imgs/love.png',
code: '11'
},
{
isBind: true,
name: '捐衣物',
url: '',
icon: '/imgs/clothes.png',
code: '11'
}
]
}, {
title: '生活',
items: [{
name: '微信',
url: '',
icon: '/imgs/wechat.png',
code: '11'
},
{
isBind: true,
name: '微信',
url: '',
icon: '/imgs/wechat.png',
code: '11'
}, {
isBind: true,
name: '火车票',
url: '',
icon: '/imgs/tick.png',
code: '11'
},
]
},
{
title: '家庭',
items: [{
isBind: true,
name: '账单',
url: '',
icon: '/imgs/bill.png',
code: '11'
}
]
}, {
title: '其他服务',
items: []
}
]
this.setData({
servers: listService
})
}, /**
* 当点击Item的时候传递过来
*/
bindNavigator: function (e) {
wx.navigateTo({
url: e.currentTarget.dataset.path,
}) },
})

微信小程序九宫格布局的更多相关文章

  1. 微信小程序的布局css样式

    微信小程序的布局css样式width: fit-content;font-size:20px;      /*设置文字字号*/color:red;           /*设置文字颜色*/font-w ...

  2. 关于微信小程序<radio-group>布局排列

    微信小程序更新以后今天<radio>全部变成垂直排列了,布局乱了. 一开始尝试给外层<view>添加display:flex;flex-direction:row:未果. 后来 ...

  3. 微信小程序~Flex布局

    有一点需要注意的是,你的小程序要求兼容到iOS8以下版本,需要开启样式自动补全.开启样式自动补全,在“设置”—“项目设置”—勾选“上传代码时样式自动补全”.

  4. 微信小程序页面布局之弹性布局-Flex介绍

    布局的传统解决方案,基于盒状模型,依赖 display 属性 + position属性 + float属性.它对于那些特殊布局非常不方便,比如,垂直居中就不容易实现. 2009年,W3C 提出了一种新 ...

  5. 微信小程序—Flex布局

    参考教程:http://www.ruanyifeng.com/blog/2015/07/flex-grammar.html     https://xluos.github.io/demo/flexb ...

  6. 转载:微信小程序view布局

    https://www.cnblogs.com/sun8134/p/6395947.html

  7. 微信小程序flex布局

    一.flex布局基础 二.相对定位和绝对定位   flex的容器和元素   主轴(左-右),交叉轴(上-下)     flex容器属性详解 flex-direction 决定元素的排列方向(默认row ...

  8. 微信小程序-flex布局中align-items和align-self区别

    首先看看菜鸟教程中关于align-items和align-self的定义 align-items:align-items 属性定义flex子项在flex容器的当前行的侧轴(纵轴)方向上的对齐方式.(对 ...

  9. 微信小程序 view 布局

    刚看到这个效果的时候还真是和ReactNative的效果一致,属性也基本的一样. view这个组件就是一个视图组件使用起来非常简单. 主要属性: flex-direction: 主要两个特性”row” ...

随机推荐

  1. ossfs常见配置错误

    以下问题出现在非root用户下 执行echo ××××> /etc/passwd-ossfs  bash: /etc/passwd-ossfs: Permission denied 使用sudo ...

  2. Struts%$#区别

    1.#符号的用途一般有三种.1)访问非根对象属性,例如示例中的#session.msg表达式,由于Struts 2中值栈被视为根对象,所以访问其他非根对象时,需要加#前缀.实际上,#相当于Action ...

  3. Ubuntu 配置 nfsserver

    https://help.ubuntu.com/lts/serverguide/network-file-system.html#nfs-installation 网络文件系统 (NFS) NFS 允 ...

  4. Linux 内核源码中likely()和unlikely()【转】

    本文转载自:http://blog.csdn.net/tigerjibo/article/details/8279183 ikely()与unlikely()在2.6内核中,随处可见,那为什么要用它们 ...

  5. Linux:NFS文件共享问题重新认识

    之前也搭建过nfs,服务器之间目录里面的文件同享也一直正常.今天有现场反映,搭建nfs后,客户端文件在服务器端看不见. 在我之前的认识里,服务器端搭建好并启动nfs服务,客户端mount后,客户端.服 ...

  6. cassandra在服务端像leveldb一样进行插入初试成功

    经过研究,决定在 cql3/QueryProcessor.java 里面下手. 这里有两个函数,第一个是 public ResultMessage process(String queryString ...

  7. codeforces 665E E. Beautiful Subarrays(trie树)

    题目链接: E. Beautiful Subarrays time limit per test 3 seconds memory limit per test 512 megabytes input ...

  8. SPOJ:Lost and survived(multiset+并查集)

    On September 22, 2004, Oceanic Flight 815 crashed on a mysterious island somewhere in the pacific. T ...

  9. [Selenium] close alert window

    public static boolean isAlertPresent(WebDriver driver) { try { driver.switchTo().alert(); return tru ...

  10. 【NOIP2017Day1T1】 小凯的疑惑

    [题目链接] 点击打开链接 [算法] px + qy不能表示的最大整数为 pq - p - q 证明见这篇博客,过程很详细,推荐阅读 : https://blog.csdn.net/qwerty112 ...