Home Web Front-end JS Tutorial Solve the problem of input box being blocked by input method

Solve the problem of input box being blocked by input method

Jun 19, 2018 pm 05:10 PM
Input box Input

Below I will share with you an article that perfectly solves the problem of the input box being blocked by the input method in the mobile web page. It has a good reference value and I hope it will be helpful to everyone.

I used to make a pop-up dialog box and fill in the information. I found that when I viewed it on my mobile phone, when filling in the information in the later input box, the input box was blocked by the input method and could only be filled in blindly.

Premise

1. The pop-up dialog box is positioned with display: fixed

2. The size of the dialog box is fixed

Solution

css part

(dlg-top and dlg-bottom is the class of the dialog box, used to determine the positioning method of the dialog box)

.dlg-top{
 position: fixed;
 top:100px;
 left:10%;
}
.dlg-bottom{
 position: fixed;
 bottom:0px;
 left:10%;
}
Copy after login

js part

"deliver-dlg" Analysis of ideas for the dialog box class

//弹出对话框时,绑定的事件
//绑定输入框获取焦点事件
$(".deliver-dlg input,.deliver-dlg textarea").focus(function(){
 var input=$(this);
 //在输入框获取焦点后,窗口改变的话,执行事件
 $(window).resize(function(){
  //判断当前输入框是否在可视窗口之外(下面)
  if($(window).height()-(input.offset().top+input.offset().height-document.body.scrollTop)<0){
   //对话框定位方式改为bottom
   $(".deliver-dlg").removeClass("dlg-top").addClass("dlg-bottom");
  }
  else{
   $(".deliver-dlg").removeClass("dlg-bottom").addClass("dlg-top");
  }
 });
});
//取消对话框时,取消事件绑定
$(".deliver-dlg input").unbind();
$(".deliver-dlg").removeClass("dlg-bottom").addClass("dlg-top");
$(window).unbind();
Copy after login

To put it simply, it is to change the positioning method of the dialog box. By default, top is used. When there is an input method, use bottom according to the situation. When the input gets focus and the window is reset (that is, the input box pops up), pay attention to binding the focus event of the input first, and then bind the window change event, because on the mobile phone, it is the input that gets the focus, and the input box pops up, causing the window to pop up. Size changes.

After the window size change event occurs, to determine whether the input box is blocked (that is, not within the visible range of the window), the method used is to use the height of the visible window ($(window).height() ) is greater than the bottom of the input box (input.offset().top input.offset().height-document.body.scrollTop) because input.offset().top represents the position of the element from the head of the document, it must be calculated The position of the element from the head of the visual window can be subtracted by how much the scroll bar has scrolled. The above is to determine whether the element is at the bottom of the visual window.

The above is what I compiled for everyone. I hope it will be helpful to everyone in the future.

Related articles:

How to control the mouse to refuse to click the button in JS

How to get the current time difference using JS

How to implement object-based management of URLs in js

How to use Generator methods in JavaScript

The above is the detailed content of Solve the problem of input box being blocked by input method. 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

Video Face Swap

Video Face Swap

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

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 pin the input method to the taskbar in Windows 11 How to pin the input method to the taskbar in Windows 11 Apr 14, 2024 pm 06:31 PM

Recently, some friends encountered the problem that the position of the input method icon changes when using the Windows 11 operating system, and they want to fix it to the taskbar for quick switching. In order to solve this problem, this article will introduce in detail the specific steps to firmly place the input method icon on the taskbar in Windows 11 system to help friends who have this need to control the input method more conveniently. Operation method 1. Use the "win+i" shortcut key to quickly enter the "Settings" interface. After entering the new interface, click the "Time and Language" option in the left column. 2. Then click "Language and Region" on the right. 3. Then click "Enter". 4. Then click the "Advanced Keyboard Settings" option. 5. Finally find "Use desktop language bar".

How to solve the problem that the candidate word box is not displayed when typing in the input method in Windows 11 system How to solve the problem that the candidate word box is not displayed when typing in the input method in Windows 11 system Apr 11, 2024 pm 05:20 PM

Recently, some users have encountered the problem that the candidate word box cannot be displayed normally when typing in the Microsoft input method when using the Windows 11 operating system. This prevents users from conveniently selecting the required Chinese characters when entering text, affecting work efficiency and user experience. . What should you do if you encounter this situation? The following brings you detailed solutions, let’s take a look. Solution 1. Right-click the input method icon in the taskbar in the lower right corner and select "More Keyboard Settings" in the option box. 2. Then click the three-dot icon on the right side of Chinese and select "Language Options" in the option list. 3. Then click the three dots icon on the right side of the input method and select "Keyboard Options" to open it. 4. Then click the "General" option. 5. Finally, press the switch under "Compatibility"

Win11 input method floating window hidden settings Win11 input method floating window hidden settings Dec 30, 2023 pm 11:24 PM

Some friends are not used to the floating window function of win11 input method, and it always feels strange to use, so they want to turn off this floating window function. Now I will introduce to you the correct operation method of closing the floating window in win11 system. Follow along. Win11 hides the input method floating window 1. Open the settings key of the computer, and then select "Time and Language". After entering, click "Enter" 2. Find "Switch Input Method" in "Advanced Keyboard Settings", and then change "Desktop Language" Click the check mark in front of "Bar", and then enter "Language Bar Options" 3. After opening, we click "Hide" here to close the language floating window.

Where to change the input method of Xiaomi mobile phone_The steps to set up the input method of Xiaomi mobile phone Where to change the input method of Xiaomi mobile phone_The steps to set up the input method of Xiaomi mobile phone Mar 25, 2024 pm 01:36 PM

1. Click [More settings] in the phone settings menu. 2. Click [Language and Input Method]. 3. Click [Input Method Management]. 4. Click [Settings] to set the input method.

How to solve the problem of lagging when switching input methods in Win10 system How to solve the problem of lagging when switching input methods in Win10 system Dec 25, 2023 pm 05:10 PM

The win10 system is the latest model. Many functions are not perfect yet, and some small bugs are prone to appear, which brings a lot of troubles to friends. Let's learn how to solve the problem of stuck when switching input methods. . How to solve the problem of unable to switch input method in win10 system 1. Click the "Start" button and open "Settings" 2. Click "Time and Language" on the right 3. Click "Language" in the left window 4. Click the input method in the right window "Options" 5. Find "Microsoft Pinyin" and click "Options" 6. Click "Vocabulary and Self-Study" in the left window 7. Turn off the switch in "Cloud Selection"

What should I do if the Win10 input method icon is missing? How to retrieve the Win10 input method icon after it is lost? What should I do if the Win10 input method icon is missing? How to retrieve the Win10 input method icon after it is lost? Feb 29, 2024 am 11:52 AM

After the Win10 input method icon is lost, many users don’t know how to retrieve it. This article will introduce simple methods to help users retrieve the Win10 input method icon, allowing you to easily switch input methods and improve work efficiency. 1. Reasons for missing input method 1. Keyboard layout problem: If you accidentally switch the keyboard layout, such as switching from Chinese to English or other languages, the input method may temporarily disappear. 2. Input method setting problem: In the system settings, we can customize the display mode of the input method. Improper settings may result in the input method being unable to be displayed or hidden. 3. Input method errors or crashes: The input method software itself may have errors or crashes, causing the input method to fail to display properly. 2. How to call up the input method Method 1: 1. Press [Win+

How to solve the problem that the word selection box cannot be displayed in the win11 input method? How to solve the problem that the word selection box cannot be displayed in the win11 input method? Jan 30, 2024 pm 05:42 PM

How to solve the problem that the word selection box is not displayed when typing in the win11 input method? Details: Recently, many users have encountered this problem when typing. There will be a lot of typos in the input content. So what should be done to display the word selection box? We can set the keyboard to turn on the display. To solve this problem, In this win11 tutorial, the editor will share the solution with the majority of users. Let’s take a look at the complete steps. How to solve the problem that the word selection box is not displayed when typing in win11 input method: 1. If it is Microsoft input method, you can click the input method icon in the lower right corner to open more keyboard settings. 3. Then click the three dots on the right side of Microsoft Input Method to open the keyboard options. 5. Finally, open the compatibility option at the bottom.

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

In Apple phones, handwriting can be set up through the keyboard page. Many users don’t know how to set it up. Users can find Add a new keyboard in the general keyboard settings and select handwriting to complete the setting. How to set up handwriting input method on Apple mobile phone? Find [Add New Keyboard] in the general keyboard of mobile phone settings. Enter the page and select [Simplified Chinese]. After selecting handwriting, click [Finish]. After setting, click [Switch Icon]. Find the [Handwriting Icon] on the page. Set up successfully and enter [Handwriting].

See all articles