微信小程式之九宮格
阿新 • • 發佈:2019-01-21
- <!--index.wxml-->
- <viewclass="container">
- <viewclass="weui-grids">
- <viewclass="weui-grid"wx:for="{{routers}}"wx:key="name">
- <navigatorurl="{{item.url}}">
- <viewclass="weui-grid__icon">
- <imagesrc=" {{item.icon}}"mode="scaleToFill"/>
- </
- <textclass="weui-grid__label">{{item.name}}</text>
- </navigator>
- </view>
- </view>
- </view>
- //index.js
- //獲取應用例項
- var app = getApp()
- Page({
- data: {
- routers: [
- {
- name: 'T1',
- url: '',
- icon: ''
- },
- {
- name: 'T2',
- url: '',
- icon: ''
- },
- {
- name: 'T3',
- url: '',
- icon: ''
- },
- {
- name: 'T4',
- url:'',
- icon:''
- },
- {
- name: 'T5',
- url:'',
- icon:''
- },
- {
- name: 'T6',
- url:'',
- icon:''
- },
- {
- name: 'T7',
- url:'',
- icon:''
- },
- {
- name: 'T8',
- url:'',
- icon:''
- },
- {
- name: 'T9',
- url:'',
- icon:''
- }
- ]
- },
- onLoad: function () {
- console.log('onLoad')
- var that = this
- }
- })
下面是控制佈局的樣式程式碼
- /**index.wxss**/
- .weui-grids {
- position: relative;
- overflow: hidden;
- }
- .weui-grids:before {
- content: " ";
- position: absolute;
- left: 0;
- top: 0;
- right: 0;
- height: 1px;
- border-top: 1pxsolid#D9D9D9;
- color: #D9D9D9;
- -webkit-transform-origin: 0 0;
- transform-origin: 0 0;
- -webkit-transform: scaleY(0.5);
- transform: scaleY(0.5);
- }
- .weui-grids:after {
- content: " ";
- position: absolute;
- left: 0;
- top: 0;
- width: 1px;
- bottom: 0;
- border-left: 1pxsolid#D9D9D9;
- color: #D9D9D9;
- -webkit-transform-origin: 0 0;
- transform-origin: 0 0;
- -webkit-transform: scaleX(0.5);
- transform: scaleX(0.5);
- }
- .weui-grid {
- position: relative;
- float: left;
- padding: 20px10px;
- width: 33.33333333%;
- box-sizing: border-box;
- }
- .weui-grid:before {
- content: