監聽鍵盤彈起與隱藏
阿新 • • 發佈:2021-07-30
window.onresize=()=>{
return(()=>{
//鍵盤彈起與隱藏都會引起視窗的高度發生變化
constresizeHeight=document.documentElement.clientHeight||document.body.clientHeight;
if(resizeHeight-0<originalHeight-0){ //當軟鍵盤彈起,在此處操作 console.log('進入到軟鍵盤彈起========='); document.querySelector('body').setAttribute('style','height:'+originalHeight+'px;'); this.scrollerHeight=resizeHeight; }else{ //當軟鍵盤收起,在此處操作
document.querySelector('body').setAttribute('style','height:100%;'); this.scrollerHeight='100%'; } })(); };
if(resizeHeight-0<originalHeight-0){ //當軟鍵盤彈起,在此處操作 console.log('進入到軟鍵盤彈起========='); document.querySelector('body').setAttribute('style','height:'+originalHeight+'px;'); this.scrollerHeight=resizeHeight; }else{ //當軟鍵盤收起,在此處操作
document.querySelector('body').setAttribute('style','height:100%;'); this.scrollerHeight='100%'; } })(); };