移動端開發時輸入框使用fixed固定在底部時,抬起鍵盤會遮擋住輸入框
監聽輸入框獲得焦點
$(function(){
$("#pinglun").focus(function(){ //輸入框獲得焦點
var tHeight = $(document).height(); //獲取當前屏幕高度,沒用到
console.log('當前屏幕高度='+tHeight)
console.log('輸入框獲得焦點')
document.getElementById("dibu1").style.position = "relative" //獲取焦點時更改定位,這個id是你定位輸入框處的id
// document.getElementById("dibu1").style.marginBottom = "cheight"+'px'
setTimeout(function(){
document.getElementById("dibu1").scrollIntoView(true) //延時定位元素移動,鍵盤抬起需要時間
},200)
}).blur(function(){
console.log('輸入框失去焦點')
document.getElementById("dibu1").style.position = "fixed" //失去焦點后改回定位狀態
});
});