美文网首页
taro开发之H5的坑:ios手机软键盘导致页面变形的完美解决方

taro开发之H5的坑:ios手机软键盘导致页面变形的完美解决方

作者: 隔壁甜言 | 来源:发表于2021-02-04 11:41 被阅读0次

举例:View中

<View className='loginInput'>
<Input name='phone' value={phone} onBlur={this.onInputBlur} onFocus={this.onInputFocus} onInput={this.phoneChange} className='loginInputCss' type='number' maxLength={11} placeholder='请输入手机号' />
</View>}
</View>

举例:jsx中

// phoneChange
phoneChange = (e) => {
this.setState({
phone: e.detail.value
})
}
// onInputFocus
onInputFocus = (e) => {
console.log('onInputFocus')
if (this.timeFocus) {
clearTimeout(this.timeFocus)
}
}
// onInputBlur
onInputBlur = (e) => {
console.log(e)
console.log('onInputBlur')
if (this.timeFocus) {
clearTimeout(this.timeFocus)
}
// 首先,判断触发事件的目标元素是否是input输入框
if (e && e.target) {
this.timeFocus = setTimeout(() => {
window.scrollTo(0, 0)
}, 20)
}
}

相关文章

网友评论

      本文标题:taro开发之H5的坑:ios手机软键盘导致页面变形的完美解决方

      本文链接:https://www.haomeiwen.com/subject/zfhbtltx.html