微信小程序?qū)崿F(xiàn)九宮格效果
本文實例為大家分享了微信小程序?qū)崿F(xiàn)九宮格效果的具體代碼,供大家參考,具體內(nèi)容如下
1.九宮格實現(xiàn)示例圖:
Tips: 說明:
使用 display: -webkit-flex;
對布局做兼容。
保證每排三個圖標(biāo)的兩對對齊,采用:justify-content: space-between;
屬性。
父元素必須設(shè)置 flex-wrap: wrap;
屬性進(jìn)行換行,否則會在一排展示。
個子元素的寬度width: 33.33333333%;
按照其占位大小分配。
使用justify-content:center;
屬性設(shè)置元素居中。
使用flex-direction: column;
和flex-wrap: wrap;
屬性設(shè)置icon
和text
元素豎直排列。
2.在 .js文件中定義數(shù)據(jù)源:
Page({ /** * 頁面數(shù)據(jù)源 */ data: { iconColor: [ 'red', 'orange', 'yellow', 'green', 'rgb(0,255,255)', 'blue', 'purple' ], iconStyle: [ { "type":"success", "size":30, "color":"#32CD32" }, { "type": "success_no_circle", "size": 30, "color": "orange" }, { "type": "info", "size": 30, "color": "yellow" }, { "type": "warn", "size": 30, "color": "green" }, { "type": "waiting", "size": 30, "color": "rgb(0,255,255)" }, { "type": "cancel", "size": 30, "color": "blue" }, { "type": "download", "size": 30, "color": "purple" }, { "type": "search", "size": 30, "color": "#C4C4C4" }, { "type": "clear", "size": 30, "color": "red" } ] } })
3.在 .wxss文件中定義樣式如下:
/* 九宮格容器布局樣式 */ .grid-item-container { display: -webkit-flex; display: flex; align-items: center; justify-content: space-between; flex-wrap: wrap; border-top: 1rpx solid #D9D9D9; } /* item容器樣式 */ .grid-item-child { display:flex; display: -webkit-flex; justify-content:center; flex-direction: column; flex-wrap: wrap; float: left; width: 33.33333333%; height: 200rpx; box-sizing: border-box; background-color: #FFFFFF; border-right: 1rpx solid #D9D9D9; border-bottom: 1rpx solid #D9D9D9; } /* icon樣式 */ .grid-item-icon { display:flex; display: -webkit-flex; justify-content:center; } /* 文本樣式 */ .grid-item-label { display:flex; display: -webkit-flex; justify-content:center; color: #666; font-size: 14px; }
4.在 .wxml文件中具體使用:
<view class='grid-item-container'> <block wx:for="{{iconStyle}}" wx:key="index"> <view class='grid-item-child'> <view> <icon class='grid-item-icon' type='{{item.type}}' size='{{item.size}}' color='{{item.color}}'/> <text class='grid-item-label'>{{item.type}}</text> </view> </view> </block> </view>
以上就是本文的全部內(nèi)容,希望對大家的學(xué)習(xí)有所幫助,也希望大家多多支持腳本之家。
相關(guān)文章
JS實現(xiàn)判斷有效的數(shù)獨(dú)算法示例
這篇文章主要介紹了JS實現(xiàn)判斷有效的數(shù)獨(dú)算法,結(jié)合實例形式分析了javascript數(shù)獨(dú)判斷的原理及相關(guān)算法實現(xiàn)、使用操作技巧,需要的朋友可以參考下2019-02-02微信小程序使用for循環(huán)動態(tài)渲染頁面操作示例
這篇文章主要介紹了微信小程序使用for循環(huán)動態(tài)渲染頁面操作,結(jié)合實例形式分析了微信小程序使用for語句獲取data數(shù)據(jù)渲染頁面相關(guān)操作技巧,需要的朋友可以參考下2018-12-12javascript contains和compareDocumentPosition 方法來確定是否HTML節(jié)點(diǎn)間的關(guān)
一個很棒的 blog 文章,是 PPK 兩年前寫的,文章中解釋了 contains() 和 compareDocumentPosition() 方法運(yùn)行在他們各自的瀏覽器上。2010-02-02淺談javascript控制HTML5的全屏操控,瀏覽器兼容的問題
下面小編就為大家?guī)硪黄獪\談javascript控制HTML5的全屏操控,瀏覽器兼容的問題。小編覺得挺不錯的,現(xiàn)在就分享給大家,也給大家做個參考。一起跟隨小編過來看看吧2016-10-10教你30秒發(fā)布一個TypeScript包到NPM的方法步驟
這篇文章主要介紹了教你30秒發(fā)布一個TypeScript包到NPM的方法步驟,文中通過示例代碼介紹的非常詳細(xì),對大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價值,需要的朋友們下面隨著小編來一起學(xué)習(xí)學(xué)習(xí)吧2019-07-07通過location.replace禁止瀏覽器后退防止重復(fù)提交
如果用戶重復(fù)提交事件,然后又后退,這樣可能會對某些數(shù)據(jù)產(chǎn)生災(zāi)難性的問題。所以今天就向大家介紹一種通過location.replace禁止瀏覽器后退按鈕的方法2014-09-09