


The first lesson explaining the basics of WeChat mini program development
Jun 11, 2018 pm 05:56 PM1. 9*9 multiplication table
test.wxml
1 2 3 4 5 6 7 |
|
test.wxss
1 2 3 |
|
Running result:
2. Window scrolling
XX.wxml
1 2 3 4 5 6 7 8 9 10 11 |
|
XX.wxss
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 |
|
This example is vertical scrolling
Attribute nameTypeDefault valueDescriptionscroll-xBooleanfalseAllow horizontal scrollingscroll-y BooleanfalseAllow vertical scrollingupper-thresholdNumber50How far away from the top/left (unit px) is the scrolltoupper event triggeredlower-thresholdNumber50How far away from the bottom/right (unit px) is the scrolltolower event triggeredscroll-topNumberSet the vertical scroll bar positionscroll-leftNumberSet the horizontal scroll bar positionscroll-into-viewString The value should be the id of a certain sub-element, then scroll to the element, and the top of the element will be aligned and scrolled Top of areabindscrolltoupperEventHandleScroll to the top/left, the scrolltoupper event will be triggeredbindscrolltolowerEventHandleScroll to the bottom/right, the scrolltolower event will be triggeredbindscrollEventHandleTriggered when scrolling, event.detail = {scrollLeft, scrollTop, scrollHeight, scrollWidth, deltaX, deltaY}
<scroll-view/> a fixed height and set the height through WXSS.
XX.wxml
1 2 3 4 5 6 7 |
|
XX.js
1 2 3 4 5 |
|
Related knowledge points
注意:其中只可放置<swiper-item/>
组件,其他节点会被自动删除。
四、弹性布局
父元素设置display:flex
相关知识点:
Flex 是 Flexible Box 的缩写,意为"弹性布局",用来为盒状模型提供最大的灵活性。
任何一个容器都可以指定为 Flex 布局。
1
2
.box{
display: flex;}
Copy after login
行内元素也可以使用 Flex 布局。
1
2
.box{
display: inline-flex;}
Copy after login
Webkit 内核的浏览器,必须加上-webkit
前缀。
1
2
3
.box{
display: -webkit-flex;
/* Safari */
display: flex;}
Copy after login
注意,设为 Flex 布局以后,子元素的float
、clear
和vertical-align
属性将失效。
二、基本概念
采用 Flex 布局的元素,称为 Flex 容器(flex container),简称"容器"。它的所有子元素自动成为容器成员,称为 Flex 项目(flex item),简称"项目"。
容器默认存在两根轴:水平的主轴(main axis)和垂直的交叉轴(cross axis)。主轴的开始位置(与边框的交叉点)叫做main start
,结束位置叫做main end
;交叉轴的开始位置叫做cross start
,结束位置叫做cross end
。
项目默认沿主轴排列。单个项目占据的主轴空间叫做main size
,占据的交叉轴空间叫做cross size
。
三、容器的属性
以下6个属性设置在容器上。
flex-direction
flex-wrap
flex-flow
justify-content
align-items
align-content
3.1 flex-direction属性
flex-direction
属性决定主轴的方向(即项目的排列方向)。
1
2
.box {
flex-direction: row | row-reverse | column | column-reverse;}
Copy after login
它可能有4个值。
row
(默认值):主轴为水平方向,起点在左端。
row-reverse
:主轴为水平方向,起点在右端。
column
:主轴为垂直方向,起点在上沿。
column-reverse
:主轴为垂直方向,起点在下沿。
3.2 flex-wrap属性
默认情况下,项目都排在一条线(又称"轴线")上。flex-wrap
属性定义,如果一条轴线排不下,如何换行。
1
2
.box{
flex-wrap: nowrap | wrap | wrap-reverse;}
Copy after login
它可能取三个值。
(1)nowrap
(默认):不换行。
(2)wrap
:换行,第一行在上方。
(3)wrap-reverse
:换行,第一行在下方。
3.3 flex-flow
flex-flow
属性是flex-direction
属性和flex-wrap
属性的简写形式,默认值为row nowrap
。
1
2
.box {
flex-flow: <flex-direction> || <flex-wrap>;}
Copy after login
3.4 justify-content属性
justify-content
属性定义了项目在主轴上的对齐方式。
1
2
.box {
justify-content: flex-start | flex-
end
| center | space-between | space-around;}
Copy after login
它可能取5个值,具体对齐方式与轴的方向有关。下面假设主轴为从左到右。
flex-start
(默认值):左对齐
flex-end
:右对齐
center
: 居中
space-between
:两端对齐,项目之间的间隔都相等。
space-around
:每个项目两侧的间隔相等。所以,项目之间的间隔比项目与边框的间隔大一倍。
3.5 align-items属性
align-items
属性定义项目在交叉轴上如何对齐。
1
2
.box {
align-items: flex-start | flex-
end
| center | baseline | stretch;}
Copy after login
它可能取5个值。具体的对齐方式与交叉轴的方向有关,下面假设交叉轴从上到下。
flex-start
:交叉轴的起点对齐。
flex-end
:交叉轴的终点对齐。
center
:交叉轴的中点对齐。
baseline
: 项目的第一行文字的基线对齐。
stretch
(默认值):如果项目未设置高度或设为auto,将占满整个容器的高度。
3.6 align-content属性
align-content
属性定义了多根轴线的对齐方式。如果项目只有一根轴线,该属性不起作用。
1
2
.box {
align-content: flex-start | flex-
end
| center | space-between | space-around | stretch;}
Copy after login
该属性可能取6个值。
flex-start
:与交叉轴的起点对齐。
flex-end
:与交叉轴的终点对齐。
center
:与交叉轴的中点对齐。
space-between
:与交叉轴两端对齐,轴线之间的间隔平均分布。
space-around
:每根轴线两侧的间隔都相等。所以,轴线之间的间隔比轴线与边框的间隔大一倍。
stretch
(默认值):轴线占满整个交叉轴。
四、项目的属性
以下6个属性设置在项目上。
<span style="font-size:16px;">order</span>
<span style="font-size:16px;">flex-grow</span>
<span style="font-size:16px;">flex-shrink</span>
<span style="font-size:16px;">flex-basis</span>
<span style="font-size:16px;">flex</span>
<span style="font-size:16px;">align-self</span>
4.1 order属性
order
属性定义项目的排列顺序。数值越小,排列越靠前,默认为0。
1
2
.item {
order: <integer>;}
Copy after login
4.2 flex-grow属性
flex-grow
属性定义项目的放大比例,默认为0
,即如果存在剩余空间,也不放大。
1
2
.item {
flex-grow: <number>;
/* default 0 */
}
Copy after login
如果所有项目的flex-grow
属性都为1,则它们将等分剩余空间(如果有的话)。如果一个项目的flex-grow
属性为2,其他项目都为1,则前者占据的剩余空间将比其他项多一倍。
4.3 flex-shrink属性
flex-shrink
属性定义了项目的缩小比例,默认为1,即如果空间不足,该项目将缩小。
1
2
.item {
flex-shrink: <number>;
/* default 1 */
}
Copy after login
如果所有项目的flex-shrink
属性都为1,当空间不足时,都将等比例缩小。如果一个项目的flex-shrink
属性为0,其他项目都为1,则空间不足时,前者不缩小。
负值对该属性无效。
4.4 flex-basis属性
flex-basis
属性定义了在分配多余空间之前,项目占据的主轴空间(main size)。浏览器根据这个属性,计算主轴是否有多余空间。它的默认值为auto
,即项目的本来大小。
1
2
.item {
flex-basis: <length> | auto;
/* default auto */
}
Copy after login
它可以设为跟width
或height
属性一样的值(比如350px),则项目将占据固定空间。
4.5 flex属性
flex
属性是flex-grow
, flex-shrink
和 flex-basis
的简写,默认值为0 1 auto
。后两个属性可选。
1
2
.item {
flex: none | [ <'flex-grow'> <'flex-shrink'>? || <'flex-basis'> ]}
Copy after login
该属性有两个快捷值:auto
(1 1 auto
) 和 none (0 0 auto
)。
建议优先使用这个属性,而不是单独写三个分离的属性,因为浏览器会推算相关值。
4.6 align-self属性
align-self
属性允许单个项目有与其他项目不一样的对齐方式,可覆盖align-items
属性。默认值为auto
,表示继承父元素的align-items
属性,如果没有父元素,则等同于stretch
。
1
2
.item {
align-self: auto | flex-start | flex-
end
| center | baseline | stretch;}
Copy after login
This attribute may take 6 values. Except for auto, the others are exactly the same as the align-items attribute.
This article explains in detail the basics of WeChat applet development. For more related content, please pay attention to the PHP Chinese website.
Related recommendations:
How to perform 2D conversion through CSS3
Detailed explanation of JavaScript variables and scope
Detailed explanation of $.ajax() method parameters
The above is the detailed content of The first lesson explaining the basics of WeChat mini program development. For more information, please follow other related articles on the PHP Chinese website!
Statement of this WebsiteThe content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn![]()
Hot Article
R.E.P.O. Energy Crystals Explained and What They Do (Yellow Crystal)2 weeks ago By 尊渡假赌尊渡假赌尊渡假赌Repo: How To Revive Teammates4 weeks ago By 尊渡假赌尊渡假赌尊渡假赌Hello Kitty Island Adventure: How To Get Giant Seeds3 weeks ago By 尊渡假赌尊渡假赌尊渡假赌How Long Does It Take To Beat Split Fiction?3 weeks ago By DDDR.E.P.O. Save File Location: Where Is It & How to Protect It?3 weeks ago By DDD![]()
Hot tools Tags
![]()
Hot Article
R.E.P.O. Energy Crystals Explained and What They Do (Yellow Crystal)2 weeks ago By 尊渡假赌尊渡假赌尊渡假赌Repo: How To Revive Teammates4 weeks ago By 尊渡假赌尊渡假赌尊渡假赌Hello Kitty Island Adventure: How To Get Giant Seeds3 weeks ago By 尊渡假赌尊渡假赌尊渡假赌How Long Does It Take To Beat Split Fiction?3 weeks ago By DDDR.E.P.O. Save File Location: Where Is It & How to Protect It?3 weeks ago By DDD![]()
Hot Article Tags
![]()
Notepad++7.3.1
Easy-to-use and free code editor
![]()
SublimeText3 Chinese version
Chinese version, very easy to use
![]()
Zend Studio 13.0.1
Powerful PHP integrated development environment
![]()
Dreamweaver CS6
Visual web development tools
![]()
SublimeText3 Mac version
God-level code editing software (SublimeText3)
![]()
Hot Topics
See all articlesHow to change real-name authentication ID card on WeChat Apr 24, 2024 am 10:58 AM
How to change real-name authentication ID card on WeChat
Can I see visitors in WeChat Moments? May 06, 2024 pm 01:30 PM
Can I see visitors in WeChat Moments?
How does WeChat know that the other party has read it? Apr 24, 2024 pm 01:45 PM
How does WeChat know that the other party has read it?
There are rumors that 'iPhone 16 may not support WeChat', and Apple's technical consultant in China said that it is communicating with Tencent about app store commissions Sep 02, 2024 pm 10:45 PM
There are rumors that 'iPhone 16 may not support WeChat', and Apple's technical consultant in China said that it is communicating with Tencent about app store commissions
How to recover deleted WeChat chat history Apr 24, 2024 am 11:36 AM
How to recover deleted WeChat chat history
Did you know that the person you blocked on WeChat has been restored? Apr 24, 2024 pm 01:34 PM
Did you know that the person you blocked on WeChat has been restored?
How to recover deleted chat history on WeChat May 06, 2024 pm 01:29 PM
How to recover deleted chat history on WeChat
![]()
Type | Default value | Instruction | |
---|---|---|---|
Boolean | false | Whether to display the panel indicator point | |
Boolean | false | Whether to automatically switch | |
Number | 0 | The index of the current page | |
Number | 5000 | Automatic switching interval | |
Number | 1000 | Sliding animation duration | |
EventHandle | The change event will be triggered when current changes, event.detail = {current: current} |