本文介绍了键盘弹出时向上滚动文本字段的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在使用html5 / javascript / jQuery / css进行移动应用开发。我在应用程序中有多个textareas。当我点击它输入时,键盘弹出(android选项卡)。但是textarea仍然保留在该页面上的位置。如何在键盘弹出时滚动页面。
I am using html5/javascript/jQuery/css for mobile app development. I have multiple textareas in the app. When I click on that to input, keyboard popup (android tab). But the textarea stays where it's on that page. How can I scroll page when keyboard pops up.
推荐答案
使用jQuery,获取textarea的值然后使用
with jQuery, get the textarea's offset().top
value then set document scroll position using scrollTop()
var $htmlOrBody = $('html, body'), // scrollTop works on <body> for some browsers, <html> for others
scrollTopPadding = 8;
$('textarea').focus(function() {
// get textarea's offset top position
var textareaTop = $(this).offset().top;
// scroll to the textarea
$htmlOrBody.scrollTop(textareaTop - scrollTopPadding);
});
这篇关于键盘弹出时向上滚动文本字段的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!