admin管理员组文章数量:1026073
I have website; a background image with an input. When I press on the input on my phone, the keyboard opens an everything gets pushed up. I would like instead the content to stay in place and keyboard just to go over the content without affecting(moving) it. I saw this solution:
input.onfocus = function () {
window.scrollTo(0, 0);
document.body.scrollTop = 0;
}
But it doesn't seem to work. I'm looking forward to your answers!
I have website; a background image with an input. When I press on the input on my phone, the keyboard opens an everything gets pushed up. I would like instead the content to stay in place and keyboard just to go over the content without affecting(moving) it. I saw this solution:
input.onfocus = function () {
window.scrollTo(0, 0);
document.body.scrollTop = 0;
}
But it doesn't seem to work. I'm looking forward to your answers!
Share Improve this question edited Jul 2, 2018 at 15:23 user8866053 asked Jul 2, 2018 at 14:44 srnesrne 331 silver badge3 bronze badges1 Answer
Reset to default 3You can take a look at this StackOverflow post, but I'll summarize the most useful parts for you:
Start off with the input's CSS as position: fixed;
. When in focus, change it to absolute
. Here is an example with JS:
if (document.getElementById("fixed") == document.activeElement) {
document.getElementById("fixed").class += "absolute"
}
Of course, that relies on CSS:
#fixed {
...
position: fixed;
}
#fixed.absolute {
position: absolute;
}
I hope this helps!
I have website; a background image with an input. When I press on the input on my phone, the keyboard opens an everything gets pushed up. I would like instead the content to stay in place and keyboard just to go over the content without affecting(moving) it. I saw this solution:
input.onfocus = function () {
window.scrollTo(0, 0);
document.body.scrollTop = 0;
}
But it doesn't seem to work. I'm looking forward to your answers!
I have website; a background image with an input. When I press on the input on my phone, the keyboard opens an everything gets pushed up. I would like instead the content to stay in place and keyboard just to go over the content without affecting(moving) it. I saw this solution:
input.onfocus = function () {
window.scrollTo(0, 0);
document.body.scrollTop = 0;
}
But it doesn't seem to work. I'm looking forward to your answers!
Share Improve this question edited Jul 2, 2018 at 15:23 user8866053 asked Jul 2, 2018 at 14:44 srnesrne 331 silver badge3 bronze badges1 Answer
Reset to default 3You can take a look at this StackOverflow post, but I'll summarize the most useful parts for you:
Start off with the input's CSS as position: fixed;
. When in focus, change it to absolute
. Here is an example with JS:
if (document.getElementById("fixed") == document.activeElement) {
document.getElementById("fixed").class += "absolute"
}
Of course, that relies on CSS:
#fixed {
...
position: fixed;
}
#fixed.absolute {
position: absolute;
}
I hope this helps!
本文标签: javascriptPrevent virtual keyboard from pushing content upStack Overflow
版权声明:本文标题:javascript - Prevent virtual keyboard from pushing content up - Stack Overflow 内容由热心网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://it.en369.cn/questions/1745613111a2159123.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论