js判断手机端键盘弹起收起

曹え 5811 发布于:2019-11-01 14:37:25

键盘弹起后 body 会增加 class="openkey"

用 openkey 调整表单的高度,让其在上半屏显示完整的表单,避免被遮挡


	$(function(){
		w = $(window).height();
		ht = $('body').scrollTop();
		$(window).resize(function(){
			inps(3);
		})
		
		$('input').focus(function(){
			inps(1);
		})
		
		
		$('input').blur(function(){
			inps(0);
		})
		
		function inps(x){
			if(x==3){
				w2 = $(window).height();
				if(w2<w){
					x = 1;
				}
				else
				{
					x = 0;
				}
			}
			if(x==0){
				$('body').removeClass('openkey');
			}
			if(x==1){
				$('body').addClass('openkey');
			}
		}
	})


觉得有用请点个赞吧!
0 422