方法一:scrollIntoViewIfNeeded:如果已经在可视区域,就不滑动
scrollIntoView:一直都滑动
this.$nextTick(()=>{
let documentInput = document.getElementsByTagName('input');
for(let i=0;i<documentInput.length;i++){
documentInput[i].onclick = function(){
this.scrollIntoViewIfNeeded(false);
}
}
})
element.scrollIntoView(); // 等同于element.scrollIntoView(true)
element.scrollIntoView(alignToTop); // Boolean型参数
element.scrollIntoView(scrollIntoViewOptions); // Object型参数
如果为true,元素的顶端将和其所在滚动区的可视区域的顶端对齐。相应的 scrollIntoViewOptions: {block: “start”, inline: “nearest”}。这是这个参数的默认值。
如果为false,元素的底端将和其所在滚动区的可视区域的底端对齐。相应的scrollIntoViewOptions: {block: “end”, inline: “nearest”}。
scrollIntoViewOptions 可选
官网
方法二:
出现当前键盘遮挡输入框事件,可能并不是键盘遮挡,而是当前页面某些定位的元素遮挡了,页面中position:absolute/fixed等等设置的元素,
解决办法:
this.$nextTick(()=>{
this.clientHeight = document.documentElement.clientHeight;
console.log(document.documentElement.clientHeight, 11111111111)
})
window.addEventListener('resize', () => {
let clientHeight = document.documentElement.clientHeight ;
console.log(clientHeight, this.clientHeight, '222222222222222')
if(clientHeight <this.clientHeight ){
this.isHidden = true;
}else{
this.isHidden = false;
}
})