Home  >  Article  >  WeChat Applet  >  Introduction to the method of making elements occupy the full screen in WeChat development

Introduction to the method of making elements occupy the full screen in WeChat development

Y2J
Y2JOriginal
2017-05-12 11:05:582538browse

This article mainly introduces the relevant information on how to make the elements occupy the entire height of the screen in the WeChat applet. Friends in need can refer to the following

Making the elements occupy the entire height of the WeChat applet Screen height implementation method

In projects, a container element is often used to fill the screen height and width, and then other elements are placed in this container element.

The width is very simplewidth:100%

But as for the height, what we know isheight :100% must be used when the height of the parent element is given.

My previous approach was to use js to get the height of the screen, and then assign it to height.

The screen height in the web page is :window.innerHeight ;

In the WeChat applet, you need to call wx.getSystemInfointerface, and then assign the value through setData

But obviously through js It is definitely not as efficient as CSS directly giving styles.

So we use another method:

Set body,html{height:100%};

Replace body and html in the web page Set it to 100% so that we can use height:100% in their child elements to make our container elements occupy the full height of the screen.

But in the WeChat applet, there is no dom object, but when we look at the debugging tool, we can see the dom tree (I don’t know how to call it either) , let’s call it that), the root node is page, so let’s try using page{height:100%}

Sure enough, it is feasible. The height fills the entire applet window.

So I can happily continue writing my small program.

【Related recommendations】

1. WeChat public account platform source code download

2. Alizi order system source code download

The above is the detailed content of Introduction to the method of making elements occupy the full screen in WeChat development. For more information, please follow other related articles on the PHP Chinese website!

Statement:
The 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