home3给组件最大div
mounted() {
this.$refs.hom3.style.height = this.$refs.hom3.clientHeight + 'px'
this.$refs.hom3.style.width = this.$refs.hom3.clientWidth + 'px'
const u = navigator.userAgent
this.isAndroid = u.indexOf('Android') > -1 || u.indexOf('Linux') > -1
window.addEventListener('resize', this.onWindowResize)
},
beforeDestroy() {
window.removeEventListener('resize', this.onWindowResize)
},
methods: {
onInputFocus() {
this.majorSelected = true
},
onWindowResize() {
if (!this.isAndroid) return
// 延迟执行布局调整,以确保页面布局稳定
setTimeout(() => {
if (this.majorSelected) {
// 当输入框获取焦点时,滚动页面以确保输入框可见
this.scrollToInput()
}
}, 100)
},
scrollToInput() {
const inputElement = this.$refs.input
if (inputElement) {
inputElement.scrollIntoView({ behavior: 'smooth', block: 'center' })
}
},
安卓唤起键盘影响定位布局 &遮挡input框
最新推荐文章于 2023-11-03 11:06:43 发布