Home WeChat Applet Mini Program Development How does the applet handle keyboard overlay input box (code attached)

How does the applet handle keyboard overlay input box (code attached)

Dec 29, 2018 am 10:54 AM
javascript mpvue Applets Input box keyboard

The content of this article is about how the mini program handles the keyboard overlay input box (with code). It has certain reference value. Friends in need can refer to it. I hope it will be helpful to you.

In the mobile terminal, when the input box is at the bottom of the page, the keyboard will cover the input box. A similar situation also occurs in the mini program, but the mini program provides some APIs. But it cannot meet the requirements. Here is a brief introduction to the solution.

Default behavior of the applet

When the keyboard overwrites the input box, no operation is performed In the case of api, the applet will push the screen upward until the input box is just above the keyboard.

That is, if it is not processed, the keyboard of the applet will not cover the input box. But In my needs, this is not enough, because part of the page is content that needs to be displayed continuously, and I don’t want to push the page up.

So I need to solve these problems through the API of the mini program.

cursor-spacing

In a relatively normal UI design, there is actually a layer of wrapper outside the input box, and it is obvious that the default behavior of the mini program is unknown, so the result is The lower part of this layer of wrapper (below the input box) will be cut off. Then it will be very ugly.

Introduce this apicursor-spacing, set it as much as you want, and leave as much as you want below the input. This number should be' The distance from the lower edge of the input box to the end of the wrapper".

The pitfall of the applet is: the unit on the document is wrong. You need to try it to know what the meaning of this attribute is, so the wrong unit results in no effect. This makes most (most) people give up. The correct unit is a string with a unit. For example, 10px or 100rpx.

adjust-position

As I mentioned just now, I want the page to not push up, but to directly push the input box up.

So I tried this API. The default is true, set it to false. The effect becomes: when the input box is clicked, the keyboard perfectly covers the input box.

So I added cursor-spacing and found that the two APIs cannot take effect at the same time. .

So the final conclusion is: Simply using the provided API cannot meet the requirements. So you can only listen to events and do it yourself.

Solution

Ideas for manually operating the input box:

  1. adjust-position is set to false.

  2. The bottom style of the wrapper in the input box is tied to the local data. And set it to absolute positioning.

  3. Change the position of the input box in the focus event.

  4. Restore the position of the input box in the blur event.

Following this idea, I encountered several problems:

How to determine the position of the input box

Found in bindfocus The height of the keyboard can be obtained in the event. After trying, the height of the keyboard is in px. So just set the bottom value to the px height.

If the relative positioning of the input box wrapper is not at the bottom of the page , the situation is more complicated. If rpx is used as the unit, the screen width and height need to be obtained to calculate the px number. Without trouble, the layout can be adjusted so that the wrapper is positioned relative to the bottom of the page.

After changing The input box loses focus immediately after style

When this happens, the behavior is as follows: when the input box is clicked, the wrapper of the input box flashes and returns to its original position. (Because it loses focus)

After many experiments, what needs to be done is to bind a local variable to the focus attribute.

Then use wx:if to hide the input box based on whether it is focus or not, and put a fake input box , after clicking, change the focus attribute to evoke the keyboard.

Implementation code: https://github.com/cwj0417/step/blob/master/src/pages/did/index.vue

The above is the detailed content of How does the applet handle keyboard overlay input box (code attached). For more information, please follow other related articles on the PHP Chinese website!

Statement of this Website
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

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

AI Hentai Generator

AI Hentai Generator

Generate AI Hentai for free.

Hot Tools

Notepad++7.3.1

Notepad++7.3.1

Easy-to-use and free code editor

SublimeText3 Chinese version

SublimeText3 Chinese version

Chinese version, very easy to use

Zend Studio 13.0.1

Zend Studio 13.0.1

Powerful PHP integrated development environment

Dreamweaver CS6

Dreamweaver CS6

Visual web development tools

SublimeText3 Mac version

SublimeText3 Mac version

God-level code editing software (SublimeText3)

How to type underline on the keyboard? How to type only underline without typing? How to type underline on the keyboard? How to type only underline without typing? Feb 22, 2024 pm 07:46 PM

Adjust the input method to English and hold down the Shift key and the minus key. Applicable model of the tutorial: Lenovo AIO520C System: Windows 10 Professional Edition: Microsoft Office Word 2022 Analysis 1 First check the Chinese and English typing of the input method and adjust it to English. 2Then hold down the Shift key and the Minus key on your keyboard at the same time. 3 Check the interface to see the underlined words. Supplement: How to quickly enter underline in Word document 1. If you need to enter an underline in Word, select the space with the mouse, then select the underline type in the font menu to enter. Summary/Notes: Be sure to change the input method to English before proceeding, otherwise the underscore cannot be successfully entered.

How to open the right-click menu through shortcut keys How to open the right-click menu through shortcut keys Jan 14, 2024 pm 03:12 PM

When our mouse temporarily loses its function, how to use keyboard shortcuts to open the right-click menu? There are two methods. One is to press the Shift+F10 shortcut key to adjust the right-click menu, and the other is to use the keyboard shortcut between windows and ctrl. Directory keys can also be used. Let’s take a look at the specific tutorial below. The first method of using keyboard shortcuts to open the right-click menu: 1. When no file is selected on the computer desktop, press the button marked in red circle on the keyboard in the picture below. This button is the button to quickly open the right-click menu. 2. You can open the right-click menu on the desktop. If you need to select an item, just use the mouse to select it. Second method 1. In fact, we can use the "Shift+F10" shortcut key to adjust the right-click menu 2

Keyboard auto-typing on Windows laptop Keyboard auto-typing on Windows laptop Feb 19, 2024 pm 05:33 PM

Computer input devices such as keyboard and mouse require human operation and cannot operate independently. The same goes for the touchpad and keyboard on Windows laptops. Text is not automatically entered, nor is the mouse clicked automatically. If something unusual happens, there must be a reason. If you encounter laptop keyboard auto-typing issues, follow the guide to fix it. Keyboard on Windows Laptop Typing Automatically When the keyboard on your Windows laptop is typing automatically, here’s how you can fix it. Check the keyboard manually Make sure the keyboard is working properly Check if the laptop is connected remotely Check if any autotyping programs are running Run a malware scan Adjust the keyboard settings Reinstall the keyboard driver Let’s know in detail

Maicong K87 three-mode mechanical keyboard adds 'hyacinth axis' and 'ice cream axis' version: Gasket structure, initial price starts at 299 yuan Maicong K87 three-mode mechanical keyboard adds 'hyacinth axis' and 'ice cream axis' version: Gasket structure, initial price starts at 299 yuan Feb 29, 2024 pm 05:00 PM

According to news from this website on February 29, Maicong today launched two versions of "Hyacinth Switch" and "Glazed Ice Cream Switch" for the K87 three-mode mechanical keyboard. The keyboard features "Gasket structure, 80% arrangement", related shaft keyboards The price information is as follows: "Hyacinth Switch" version: initial price is 299 yuan. "Liuguang Ice Cream Switch" version: initial price is 379 yuan. According to reports, the series of keyboards use Gasket structure, 87-key 80% arrangement, full-key rollover, and support thermal For plugging and unplugging, it claims to use "original/MDA two-color PBT keycaps", uses a 1.2mm single-key slotted PCB (lower lamp position), is equipped with RGB lighting effects, and has a magnetic absorption nameplate design. In addition, this keyboard is equipped with a 6000 mAh battery and a wireless delay of 3ms. The official size and size of the keyboard have not been announced.

How to assign Copilot buttons on any keyboard in Windows 11 How to assign Copilot buttons on any keyboard in Windows 11 Feb 20, 2024 am 10:33 AM

Windows 11 computer keyboards that will be launched in the next few months will have a new Copilot key. This key allows users to easily enter co-pilot mode by pressing a designated button without upgrading a new PC. This guide will detail how to set up the copilot button on any Windows 11 keyboard. Microsoft recently announced that they have made important progress in advancing artificial intelligence-assisted driving. Windows 11 will add a dedicated Copilot key to further enhance the experience of PC users. This hardware change represents the first major upgrade to Windows PC keyboards in thirty years. In the coming months, new Windows 11 computers will feature a new Copilot key design on the keyboard

VGN co-branded 'Elden's Circle' keyboard and mouse series products are now on the shelves: Lani / Faded One custom theme, starting from 99 yuan VGN co-branded 'Elden's Circle' keyboard and mouse series products are now on the shelves: Lani / Faded One custom theme, starting from 99 yuan Aug 12, 2024 pm 10:45 PM

According to news from this site on August 12, VGN launched the co-branded "Elden Ring" keyboard and mouse series on August 6, including keyboards, mice and mouse pads, designed with a customized theme of Lani/Faded One. The current series of products It has been put on JD.com, priced from 99 yuan. The co-branded new product information attached to this site is as follows: VGN丨Elden Law Ring S99PRO Keyboard This keyboard uses a pure aluminum alloy shell, supplemented by a five-layer silencer structure, uses a GASKET leaf spring structure, has a single-key slotted PCB, and the original height PBT material Keycaps, aluminum alloy personalized backplane; supports three-mode connection and SMARTSPEEDX low-latency technology; connected to VHUB, it can manage multiple devices in one stop, starting at 549 yuan. VGN丨Elden French Ring F1PROMAX wireless mouse the mouse

How to set up handwriting input method on Apple mobile phone keyboard How to set up handwriting input method on Apple mobile phone keyboard Mar 08, 2024 pm 02:30 PM

Apple mobile keyboard users want to set up the handwriting input method, but don’t know how to do it. It’s actually very simple. Users can directly select the handwriting input method in the phone’s keyboard settings. If not, they can also manually add a handwriting input method. How to set the handwriting input method on the Apple mobile phone keyboard A: Enable the handwriting input method directly in the keyboard settings 1. When Apple users use the input method, the handwriting input method is enabled by default. 2. Users only need to click and hold the lower left corner to select the handwriting input method while typing. 3. If the user does not have a handwriting input method in his mobile phone, he can also add it manually. 4. The user enters the settings, finds the universal keyboard settings, and adds the handwriting input option to the first keyboard. 5. Use handwriting input method to

How to set the skin for the WeChat keyboard How to set the skin for the WeChat keyboard How to set the skin for the WeChat keyboard How to set the skin for the WeChat keyboard Mar 13, 2024 am 09:04 AM

How to set the skin for WeChat keyboard? WeChat Keyboard is a very smart mobile phone input method software. This software has many user-friendly functions. It allows users to choose their own input mode and find the expressions they want as quickly as possible on this software. send out. This software also allows users to change the skin of the keyboard themselves. Many users are not sure how to change the skin. The editor below has compiled the skin changing methods for your reference. How to set the WeChat keyboard skin In WeChat, SMS or other applications that require the use of the keyboard on your phone, you can click the input method settings icon in the upper left corner of the keyboard to enter the settings page to view the function setting options for various input methods. 2. Click "Personalized Skin" on the settings page of the input method.

See all articles