foreword
When doing some comments or other similar functions, we often encounter the following two problems:
- Maybe we want to automatically focus the input box at the bottom when the comment icon is clicked, but we found that the focus event calling the input box does not work.
- After the input box is focused, it is blocked by the pop-up keyboard, and you have to slide down to see the input box
solve
setTimeout(() => {
//解决第一个问题,myInput是获取到的输入框元素
myInput.value.focus()
//解决第二个问题
document.body.scrollTop = document.body.scrollHeight;
}, 100);