ios safari input fixed 软键盘里的爱恨情仇
请看第一题:
为什么我的input获取焦点后,被输入法遮住了。
解决办法:
源码:
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Title</title>
<script src="jquery-3.1.0.js"></script>
<style>
input{display: block}
</style>
</head>
<body>
<input type="text" value="123456">
<input type="text" value="123456">
<input type="text" value="123456">
<input type="text" value="123456">
<input type="text" value="123456">
<input type="text" value="123456">
<input type="text" value="123456">
<input type="text" value="123456">
<input type="text" value="123456">
<input type="text" value="123456">
<input type="text" value="123456">
<input type="text" value="123456">
<input type="text" value="123456">
<input type="text" value="123456">
<input type="text" value="123456">
<input type="text" value="123456">
<input type="text" value="123456">
<input type="text" value="123456">
<input type="text" value="123456">
<input type="text" value="123456">
<input type="text" value="123456">
<input type="text" value="123456">
<input type="text" value="123456">
<input type="text" value="123456">
<input type="text" value="123456">
<input type="text" value="123456">
<input type="text" value="123456">
<input type="text" value="123456">
<input type="text" value="123456">
<input type="text" value="123456">
<input type="text" value="123456">
<input type="text" value="123456">
<input type="text" value="123456">
<input type="text" value="123456">
<input type="text" value="123456">
<input type="text" value="123456">
<input type="text" value="123456">
<input type="text" value="123456">
<input type="text" value="123456">
<input type="text" value="123456">
<input type="text" value="123456">
<input type="text" value="123456">
<input type="text" value="123456">
<input type="text" value="123456">
<input type="text" value="123456">
<input type="text" value="123456">
<input type="text" value="123456">
<input type="text" value="123456">
<input type="text" value="123456">
<input type="text" value="123456">
<input type="text" value="123456">
<input type="text" value="123456">
<input type="text" value="123456">
<input type="text" value="123456">
<input type="text" value="123456">
<input type="text" value="123456">
<input type="text" value="123456">
<input type="text" value="123456">
<input type="text" value="123456">
<input type="text" value="123456">
<input type="text" value="123456">
<input type="text" value="123456">
<input type="text" value="123456">
<input type="text" value="123456">
<input type="text" value="123456">
<input type="text" value="123456">
<input type="text" value="123456">
<input type="text" value="123456">
<input type="text" value="123456">
<input type="text" value="123456">
<input type="text" value="123456">
<input type="text" value="123456">
<input type="text" value="123456">
<input type="text" value="123456">
<input type="text" value="123456">
<input type="text" value="123456">
<input type="text" value="123456">
<input type="text" value="123456">
<input type="text" value="123456">
<input type="text" value="123456">
<input type="text" value="123456">
<input type="text" value="123456">
<input type="text" value="123456">
<input type="text" value="123456">
<input type="text" value="123456">
<input type="text" value="123456">
<input type="text" value="123456">
<input type="text" value="123456">
<input type="text" value="123456">
<input type="text" value="123456">
<input type="text" value="123456">
<input type="text" value="123456">
<input type="text" value="123456">
<input type="text" value="123456">
<input type="text" value="123456">
<input type="text" value="123456">
<input type="text" value="123456">
<input type="text" value="123456">
<input type="text" value="123456">
<input type="text" value="123456">
<input type="text" value="123456">
<input type="text" value="123456">
<input type="text" value="123456">
<input type="text" value="123456">
<input type="text" value="123456">
<input type="text" value="123456">
<input type="text" value="123456">
<input type="text" value="123456">
<input type="text" value="123456">
<input type="text" value="123456">
<input type="text" value="123456">
<input type="text" value="123456">
<input type="text" value="123456">
<input type="text" value="123456">
<input type="text" value="123456">
<input type="text" value="123456">
<input type="text" value="123456">
<input type="text" value="123456">
<input type="text" value="123456">
<input type="text" value="123456">
<input type="text" value="123456">
<input type="text" value="123456">
<input type="text" value="123456">
<input type="text" value="123456">
<input type="text" value="123456">
<input type="text" value="123456">
<input type="text" value="123456">
<input type="text" value="123456">
<input type="text" value="123456">
<input type="text" value="123456">
<input type="text" value="123456">
<input type="text" value="123456">
<input type="text" value="123456">
<input type="text" value="123456">
<input type="text" value="123456">
<input type="text" value="123456">
<input type="text" value="123456">
<input type="text" value="123456">
<input type="text" value="123456">
<input type="text" value="123456">
<input type="text" value="123456">
<input type="text" value="123456">
<input type="text" value="123456">
<input type="text" value="123456">
<input type="text" value="123456">
<input type="text" value="123456">
<input type="text" value="123456">
<input type="text" value="123456">
<input type="text" value="123456">
<input type="text" value="123456">
<input type="text" value="123456">
<input type="text" value="123456">
<input type="text" value="123456">
<input type="text" value="123456">
<input type="text" value="123456">
<input type="text" value="123456">
<input type="text" value="123456">
<input type="text" value="123456">
<input type="text" value="123456">
<input type="text" value="123456">
<input type="text" value="123456">
<input type="text" value="123456">
<input type="text" value="123456">
<input type="text" value="123456">
<input type="text" value="123456">
<input type="text" value="123456">
<input type="text" value="123456">
<input type="text" value="123456">
<input type="text" value="123456">
<input type="text" value="123456">
<input type="text" value="123456">
<input type="text" value="123456">
<input type="text" value="123456">
<input type="text" value="123456">
<input type="text" value="123456">
<input type="text" value="123456">
<input type="text" value="123456">
<input type="text" value="123456">
<input type="text" value="123456">
<input type="text" value="123456">
<input type="text" value="123456">
<input type="text" value="123456">
<input type="text" value="123456">
<input type="text" value="123456">
<input type="text" value="123456">
<input type="text" value="123456">
<input type="text" value="123456">
<input type="text" value="123456">
<input type="text" value="123456">
<input type="text" value="123456">
<input type="text" value="123456">
<input type="text" value="123456">
<input type="text" value="123456">
</body>
<script>
//处理input输入框被输入法遮住
function inputIos(inputBox){
var inputF = $(inputBox).find('input');//找到对应的input
if(inputF == document.activeElement){
//获取焦点时用喔
setTimeout(function(){
var inputIsNotInView = notInView(),
Width = window.innerWidth,
Height = window.innerHeight;
if(inputIsNotInView){
if(Width != 750){
var bottomAdjust = (Height - window.innerHeight - 88) + 'px';
$(inputBox).css('bottom',bottomAdjust);
}else {
var bottomAdjust = (Height - window.innerHeight - 88 - 432) + 'px';
$(inputBox).css('bottom',bottomAdjust);
}
}
},600); }else {
//失去焦点时用喔
var inputIsNotInView=notInView();
if(inputIsNotInView){
$(inputBox).css({'opacity':0,bottom:0});
setTimeout(function(){
$(inputBox).css('opacity',1);
},600)
}
} //------------------------------
function notInView(){
var bottom = inputBox.getBoundingClientRect().bottom;
if (window.innerHeight - bottom < 0){
return true;
}else {
return false;
}
};
}
</script>
</html>
一向如此任性,从不解释为什么,为什么?这是去年的代码,所以,我也忘了……
请看第二题:
今天一个辞职很久的前端姐姐问我一个在ios safari浏览器中为什么我的css为position:fixed的header居然被软键盘干没了。
于是我花了将近半小时,借了一部传说中的5s开始了实验。
于是,请看源码:
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>因为爱情</title>
<meta name="viewport" content="width=device-width, initial-scale=1.0,maximum-scale=1.0,
user-scalable=no">
<style type="text/css">
body{position:relative}
header{position:fixed;top:0;left:0;background:yellow;}
main{height:500px;overflow:scroll}
</style>
</head>
<body>
<header id='head'>我就是骄傲的头部!我不动!</header> <main style=''>
<div style='background:red;height:300px;'></div>
<div style='background:green;height:300px;'></div>
</main>
<footer>
<input type="text" value='我就在这里' id='input'/>
</footer>
</body>
<script type="text/javascript" src='https://cdn.bootcss.com/jquery/3.2.1/jquery.min.js'></script>
<script type="text/javascript">
$('#input').on('focus',function(){
$("#head").css("position", "absolute");
window.onscroll=function(){
var top = $(document).scrollTop();
$("#head").css("top",top);
}
/* setTimeout(function(){ },1500) */
}).on('blur',function(){
$('header').css({
"position":"fixed",
'top':0,
'left':0
})
})
</script>
</html>
因为是刚刚写的,所以我有话说:
首先百度了也google了。发现是苹果的bug,这个bug没啥好解释的,比较恶心就是了,他的软键盘在input获取焦点后弹起,然后就将我的"position":"fixed",硬生生掰成了"position", "absolute";这让我这个直男怎么可以接受!
你这个样子,我只好将计就计了。
于是我就发现了滚动条高度,然后做一个滚动条监听事件,然后这样平滑的解决了header被顶出去的bug。当然,失去焦点的时候,我们的fixed还是可以正常使用的。
嗯,就这样,我是宋宇,如果不小心帮助到了你,我很荣幸。
ios safari input fixed 软键盘里的爱恨情仇的更多相关文章
- IOS下 input 被软键盘方案遮盖问题解决
		
前言: 并没有完美解决 ! 场景: 最近在做企业微信H5的一个项目,里面有个动态列表页,开始输入框是隐藏的,点击评论才会出现并让 input 聚焦.经过测试在安卓上面应该没什么问题,但是iOS上面会出 ...
 - input获取焦点软键盘弹出影响定位
		
解决移动端底部fixed和input获取焦点软键盘弹出影响定位的问题$(document).ready(function() { var ...
 - 页面的input唤醒软键盘再收起后,页面会出现软键盘高度的空白背景
		
微信浏览器在版本6.7.4及以上会有这个bug:页面的input唤醒软键盘再收起后,页面会出现软键盘高度的空白背景,触摸到滚动条会消失恢复! 解决代码 后台框架嵌入iframe的情景,iframe内部 ...
 - web移动端fixed布局和input等表单的爱恨情仇 - 终极BUG,完美解决
		
[问题]移动端开发,ios下当fixed属性和输入框input(这里不限于input,只要可以调用移动端输入法的都包括,如:textarea.HTML5中contenteditable等),同时存在的 ...
 - ios移动输入框被软键盘遮挡
		
页面输入框会出现被软键盘挡住的问题: 解决方法:获取input点击事件设置body高度 $('input').bind('click',function(e){ var $this = $(this) ...
 - iOS自动自动隐藏软键盘
		
自动隐藏软键盘,分为两步,一个是单击软键盘外部任意空间:另外一个是单击软键盘上的return键.下面依次实现 单击软键盘外部空间键隐藏软键盘: 一:在viewDidLoad中添加一个UITabGest ...
 - ionic 项目中ios上遇到的软键盘输入法自动弹出的问题
		
一. 安装插件 cordova plugin add ionic-plugin-keyboard 二. 软键盘显示监听 window.addEventListener('native.keyboar ...
 - 移动端解决fixed和input获取焦点软键盘弹出影响定位的问题
		
场景描述, 当document的高度不够window的高度时候,如在ip6中文档的高度比窗体的高度小,到底设计在最下方的区域没有在窗体最下方,就留有空白地方如下图的灰色部分 1. 解决初始化文档高度, ...
 - fixed固定时弹窗上的input被软键盘遮住的问题
		
<div class="pwhCover"> <div class="pwhCon"> <div class="pwhT ...
 
随机推荐
- poj 3254 状态压缩
			
Corn Fields Time Limit: 2000MS Memory Limit: 65536K Total Submissions: 15285 Accepted: 8033 Desc ...
 - Python使用redis介绍
			
一.Redis的介绍 redis是业界主流的key-value nosql 数据库之一.和Memcached类似,它支持存储的value类型相对更多,包括string(字符串).list(链表).se ...
 - 「Linux」centos7安装python
			
•安装python3.6可能使用的依赖 yum install openssl-devel bzip2-devel expat-devel gdbm-devel readline-devel sqli ...
 - go defer注意点,很容易出错的!!!
			
1:defer是在return之前执行的 函数返回的过程是这样的:先给返回值赋值,然后调用defer表达式,最后才是返回到调用函数中 返回值 = xxx 调用defer函数 空的return fun ...
 - CF760 C. Pavel and barbecue 简单DFS
			
LINK 题意:给出n个数,\(a_i\)代表下一步会移动到第\(a_i\)个位置,并继续进行操作,\(b_i\)1代表进行一次翻面操作,要求不管以哪个位置上开始,最后都能满足 1.到达过所有位置 2 ...
 - ZOJ 3787  Access System 水
			
LINK:http://acm.zju.edu.cn/onlinejudge/showProblem.do?problemCode=3787 思路:结构体 时间转化为秒记录下最小并且排序就好了 /** ...
 - 【CodeForces】960 F. Pathwalks 主席树+动态规划
			
[题目]F. Pathwalks [题意]给定n个点m条边的有向图,可能不连通有重边有自环.每条边有编号 i 和边权 wi ,求最长的路径(可以经过重复节点)满足编号和边权都严格递增.n,m,wi&l ...
 - jQuery.Event的一些用法
			
直接写用法 //创建一个事件 var event = $.Event("事件类型",["定义的事件参数最终将出现在e1中"]); //绑定一个处理器 $(obj ...
 - 60、简述 yield和yield from关键字。
			
1.可迭代对象与迭代器的区别 可迭代对象:指的是具备可迭代的能力,即enumerable. 在Python中指的是可以通过for-in 语句去逐个访问元素的一些对象,比如元组tuple,列表list ...
 - 56、isinstance作用以及应用场景?
			
isinstance作用:来判断一个对象是否是一个已知的类型: 其第一个参数(object)为对象,第二个参数为类型名(int...)或类型名的一个列表((int,list,float)是一个列表). ...