WeChat applet realizes the nine-square grid effect

WeChat applet realizes the nine-square grid effect

This article shares the specific code for the WeChat applet to achieve the nine-square grid effect for your reference. The specific content is as follows

1. Example diagram of Jiugongge implementation:

Tips: Description:

Use display: -webkit-flex; to make the layout compatible.

To ensure that the two pairs of three icons in each row justify-content: space-between; property.

The parent element must set flex-wrap: wrap; property to wrap, otherwise it will be displayed in one row.

The width: 33.33333333%; allocated according to its occupied size.

Use justify-content:center; property to center the element.

Use flex-direction: column; and flex-wrap: wrap; properties to set icon and text elements to be arranged vertically.

2. Define the data source in the .js file:

Page({

  /**
   * Page data source */
  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. Define the style in the .wxss file as follows:

 /*
  Nine-grid container layout style*/
.grid-item-container {
  display: -webkit-flex;
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-wrap: wrap;
  border-top: 1rpx solid #D9D9D9;
}

/*
  Item container style*/
.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 style*/
.grid-item-icon {
  display:flex;
  display: -webkit-flex;
  justify-content:center;
}

/*
 Text style*/
.grid-item-label {
  display:flex;
  display: -webkit-flex;
  justify-content:center;
  color: #666;
  font-size: 14px;
}

4. Specific use in .wxml files:

<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>

The above is the full content of this article. I hope it will be helpful for everyone’s study. I also hope that everyone will support 123WORDPRESS.COM.

You may also be interested in:
  • WeChat applet implements flip card lottery animation
  • WeChat Mini Program Version of Flip Card Game
  • WeChat applet implements nine-square lottery
  • WeChat applet project practice: Nine-grid implementation and item jump function
  • WeChat applet nine-square grid example code
  • WeChat applet realizes the nine-square grid flip animation

<<:  How to upgrade all Python libraries in Ubuntu 18.04 at once

>>:  Basic usage analysis of Explain, a magical tool for MySQL performance optimization

Recommend

A brief discussion on the calculation method of key_len in mysql explain

The MySQL explain command can analyze the perform...

Two ways to completely delete users under Linux

Linux Operation Experimental environment: Centos7...

How is MySQL transaction isolation achieved?

Table of contents Concurrent scenarios Write-Writ...

Detailed explanation of the processing of the three Docker Nginx Logs

Because colleagues in the company need Nginx log ...

Why is your like statement not indexed?

Preface This article aims to explain the most bor...

Thoroughly understand JavaScript prototype and prototype chain

Table of contents Preface Laying the foundation p...

How to set mysql permissions using phpmyadmin

Table of contents Step 1: Log in as root user. St...

How does MySQL implement ACID transactions?

Preface Recently, during an interview, I was aske...

How MySQL Select Statement is Executed

How is the MySQL Select statement executed? I rec...

How to implement JavaScript output of Fibonacci sequence

Table of contents topic analyze Basic solution Ba...

Practical record of MySQL 5.6 master-slave error reporting

1. Problem symptoms Version: MySQL 5.6, using the...

Bootstrap3.0 study notes table related

This article mainly explains tables, which are no...

React Router V6 Updates

Table of contents ReactRouterV6 Changes 1. <Sw...