gpt4 book ai didi

javascript - 滚动后无法聚焦输入?

转载 作者:行者123 更新时间:2023-12-03 06:58:43 25 4
gpt4 key购买 nike

在移动浏览器中,当焦点输入文本时,我希望此输入滚动到顶部

$(this.$el).find('input, textarea').on('focus', function(e) {
setTimeout((function() {
var pos = $(this).position();
if (pos.top > window.innerHeight) {
var scrollTopOffset = pos.top - window.innerHeight + this.offsetHeight + 10
$scroller.scrollTop($scroller.scrollTop() + scrollTopOffset)
}
}).bind(this), 500); // After the keyboard up
$(this).focus()
})

输入滚动到正确位置后,无法聚焦输入

触摸输入然后焦点就可以了,之后键盘向上然后输入滚动到顶部,然后松开焦点<​​/p>

滚动后如何聚焦输入?

最佳答案

我已经尝试过,通过模拟移动浏览器,它可以工作。

$('input, textarea').on('focus', function() {
document.body.scrollTop = $(this).offset().top;
$(this).focus();
});

关于javascript - 滚动后无法聚焦输入?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37152810/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com