


Detailed introduction to WXML, WXSS and JS for WeChat development
This article mainly introduces the relevant information about the introduction and detailed explanation of WXML, WXSS and JS of the WeChat applet. Friends in need can refer to it.
I spent a lot of time a few days ago. Then list some experimental results for your reference.
There is still a big difference between the simulation using development tools and the real machine. I also suggest that it is more reliable to debug on a real machine.
1. WXML(HTML)
1.1 The WXML of the applet is not as tolerant as HTML, and the single tag must end with />. Otherwise, an error will be reported.
1.2 The officially recommended basic tag
1.3 The scroll-top and scroll-left of scroll-view can modify the scroll position of scroll-view. However, after the user scrolls, the applet will not change the assignment of scroll-top and scroll-left (it is not two-way synchronization). If you use setData to modify it at this time, the assignment of scroll-top and scroll-left will be the same as the last value. The applet will not apply this modification, so the performance is that the setting does not take effect. At this time, you can only set another value first and then set it back (it can also be reflected that the setData method is synchronous). scroll-view obtains the scroll position, which can only be obtained through the bindscroll callback function, so if you need to obtain the scroll position, please save it yourself. scroll-view still has the stinky problem of webview's scroll. If the first action is to scroll down at the top position, it will cause the hand to be unable to scroll no matter how you slide it. Set scroll-top not to 0, but to 1. alright.
1.4 input currently only supports text on the left, and others are not possible (the simulator can). If you make a form, it is recommended to put input and other form elements in the form. When from triggers submit, it will return the name-value of all internal form elements. Otherwise, it can only be obtained by binding the change events of all form elements, which is very troublesome.
1.5 Only checkbox-group has a change event, and a single checkbox does not. If you only have one checkbox, and you think it is troublesome and unsightly to have a checkbox-group outside, you can use switch type="checkbox" instead. . (WeChat mini program application number communication group 563752274)
1.6 Map construction is currently loaded directly on the first page of the app and will fail to load. Need to be added after onLoad. You can first use wx:if="false" and then change it to true after onLoad.
1.7 map, canvas is like covering a native component on the webview. They cannot be covered by overflow and elements. You can think that z-index cannot be placed on top of it no matter how high it is written. Therefore, it is not recommended to make elastic layers and masking layers on the page. The canvas cannot be placed in the scroll-view and the scroll will be positioned at the initial position. If you set the background color for the canvas, you will find that the background color block scrolls with it, but the image does not scroll.
2. WXSS(CSS)
2.1 WXSS is very similar to CSS, basically all CSS is supported, and the mini program also provides the rpx unit. One screen width is 750rpx. It is recommended to use this as a layout. However, there are some minor differences that I will list below
2.2 WXSS does not support nested braces ({{}}). So key-frames and CSS animation are not available, but transition is available.
2.3 Currently, the fonts introduced in the test are not available, and the content mentioned in WXML cannot be used in SVG. Therefore, icons can currently only be made in the form of pictures.
2.4 Local resources cannot be introduced into WXSS, only online resources can be used (the simulator is available, but don’t believe it), and base64 can be used. (WeChat applet application account communication group 563752274)
2.5 WXSS rule does not support set association. So you cannot write body .main {background:#000;} like this. So it’s quite laborious to write. Each class is very long, otherwise there is fear of duplication of names. However, it supports writing like li.current {color: red;}, supports after, beforepseudo-class, but does not support first-child last-child nth -child pseudo-classes.
2.6 The coverage relationship between app.wxss and the wxss of each page is: If there is a rule with the same name, the page will overwrite the app, not the merge.
3. JS
3.1 The running environment of JS and the running environment of view are isolated. JS can only change the view through event acquisition timing and setData method to modify data.
3.2 JS currently has a big problem that it is unable to obtain the px-level width and height of the page. The units of all event callbacks are px-level instead of rpx, but the conversion relationship between the current rpx and px is not known. For example, you use canvas to draw pictures. You don’t even know where the boundary is, which is really annoying.
3.3 As mentioned above, the setData method will not trigger view modification if the previous value and the next value are the same (see 1.3)
3.4 It can be used when using navigate to jump. The queryString method follows the relative address, and the onLoad event will be passed in the input parameter (which will be converted into an object), but there is no official data communication mechanism when navigating back. You can use getApp() to get the global object, add something to it, and implement it yourself. I won’t talk about the maximum number of 5 navigate.
3.5 After canvas getActions is called, the actions will be cleared. That is, getActions is called twice in a row, and the second time is an empty array.
3.6 The developer tool is written by nw. I looked at the source code of the skirt. The WXML in the developer tool does have a parser and reassembly process. But it does not mean that the gadget is native. From the support of CSS to the similarity of some bugs in webview, I still think it looks like webview, but components such as map and canvas use native view and then cover it on webview. a feeling of. But anyway, the fact that auto-focus can automatically call out the keyboard is already a great compliment.
【Related recommendations】
1. WeChat public account platform source code download
3. WeChat LaLa Takeaway 2.2.4 Decrypted Open Source Version of WeChat Rubik’s Cube Source Code
The above is the detailed content of Detailed introduction to WXML, WXSS and JS for WeChat development. For more information, please follow other related articles on the PHP Chinese website!

Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

Video Face Swap
Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Article

Hot Tools

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

Face detection and recognition technology is already a relatively mature and widely used technology. Currently, the most widely used Internet application language is JS. Implementing face detection and recognition on the Web front-end has advantages and disadvantages compared to back-end face recognition. Advantages include reducing network interaction and real-time recognition, which greatly shortens user waiting time and improves user experience; disadvantages include: being limited by model size, the accuracy is also limited. How to use js to implement face detection on the web? In order to implement face recognition on the Web, you need to be familiar with related programming languages and technologies, such as JavaScript, HTML, CSS, WebRTC, etc. At the same time, you also need to master relevant computer vision and artificial intelligence technologies. It is worth noting that due to the design of the Web side

How to use JS and Baidu Map to implement map pan function Baidu Map is a widely used map service platform, which is often used in web development to display geographical information, positioning and other functions. This article will introduce how to use JS and Baidu Map API to implement the map pan function, and provide specific code examples. 1. Preparation Before using Baidu Map API, you first need to apply for a developer account on Baidu Map Open Platform (http://lbsyun.baidu.com/) and create an application. Creation completed

Essential tools for stock analysis: Learn the steps to draw candle charts in PHP and JS. Specific code examples are required. With the rapid development of the Internet and technology, stock trading has become one of the important ways for many investors. Stock analysis is an important part of investor decision-making, and candle charts are widely used in technical analysis. Learning how to draw candle charts using PHP and JS will provide investors with more intuitive information to help them make better decisions. A candlestick chart is a technical chart that displays stock prices in the form of candlesticks. It shows the stock price

How to use PHP and JS to create a stock candle chart. A stock candle chart is a common technical analysis graphic in the stock market. It helps investors understand stocks more intuitively by drawing data such as the opening price, closing price, highest price and lowest price of the stock. price fluctuations. This article will teach you how to create stock candle charts using PHP and JS, with specific code examples. 1. Preparation Before starting, we need to prepare the following environment: 1. A server running PHP 2. A browser that supports HTML5 and Canvas 3

Overview of how to use JS and Baidu Maps to implement map click event processing: In web development, it is often necessary to use map functions to display geographical location and geographical information. Click event processing on the map is a commonly used and important part of the map function. This article will introduce how to use JS and Baidu Map API to implement the click event processing function of the map, and give specific code examples. Steps: Import the API file of Baidu Map. First, import the file of Baidu Map API in the HTML file. This can be achieved through the following code:

How to use JS and Baidu Maps to implement the map heat map function Introduction: With the rapid development of the Internet and mobile devices, maps have become a common application scenario. As a visual display method, heat maps can help us understand the distribution of data more intuitively. This article will introduce how to use JS and Baidu Map API to implement the map heat map function, and provide specific code examples. Preparation work: Before starting, you need to prepare the following items: a Baidu developer account, create an application, and obtain the corresponding AP

With the rapid development of Internet finance, stock investment has become the choice of more and more people. In stock trading, candle charts are a commonly used technical analysis method. It can show the changing trend of stock prices and help investors make more accurate decisions. This article will introduce the development skills of PHP and JS, lead readers to understand how to draw stock candle charts, and provide specific code examples. 1. Understanding Stock Candle Charts Before introducing how to draw stock candle charts, we first need to understand what a candle chart is. Candlestick charts were developed by the Japanese

The relationship between js and vue: 1. JS as the cornerstone of Web development; 2. The rise of Vue.js as a front-end framework; 3. The complementary relationship between JS and Vue; 4. The practical application of JS and Vue.
