我们公司有一个页面底部用到了fixed样式,每当弹出键盘的时候,IOS下fixed就会走样(据我所知android没有该问题)。

为此之前我经过产品的同意做了简单的处理(方法1)。

方法一:

focus的时候让fixed块position变为relative,这是最简单的处理方法。

下面是我的小demo

<!DOCTYPE html>
<html>
<head>
<title></title>
<meta charset="utf-8">
<meta http-equiv="pragma" content="no-cache" />
<meta name="viewport" content="width=device-width, initial-scale=1.0, minimum-scale=1.0, maximum-scale=1.0, user-scalable=no,minimal-ui" />
<style>
* {
padding: 0;
margin: 0;
}
.input {
margin:10px 10px 400px 10px;
width: 200px;
height: 30px;
border: 1px solid #ccc;
display: block;
}
.next {
width: 100%;
height: 44px;
line-height: 44px;
background: orangered;
position: fixed;
bottom:0;
color:#fff;
text-align: center;
}
.pos-rel {
position: relative;;
}
</style>
<script src="../js/zepto.js"></script>
</head>
<body>
<section class="content"> <input class="input" type="text" />
<input class="input" type="text" />
<input class="input" type="text" /> <div class="next">
下一步
</div>
</section> <script>
$(function() {
var isIOS = (/iphone|ipad/gi).test(navigator.appVersion); if (isIOS) {
$('.content').on('focus', 'input', function () {
$('.next').addClass('pos-rel');
}).on('focusout', 'input', function () {
$('.next').removeClass('pos-rel');
});
}
});
</script>
</body>
</html>

方法二:

position:absolute;每次滚动的时候重新算位置。

下面是我的小demo,touch的时候作了隐藏处理,input focusout和window resize的时候作了fixed位置重新计算。

<!DOCTYPE html>
<html>
<head>
<title></title>
<meta charset="utf-8">
<meta http-equiv="pragma" content="no-cache" />
<meta name="viewport" content="width=device-width, initial-scale=1.0, minimum-scale=1.0, maximum-scale=1.0, user-scalable=no,minimal-ui" />
<style>
* {
padding: 0;
margin: 0;
}
.input {
margin:10px 10px 400px 10px;
width: 200px;
height: 30px;
border: 1px solid #ccc;
display: block;
}
.next {
width: 100%;
height: 44px;
line-height: 44px;
background: orangered;
position: absolute;
color:#fff;
text-align: center;
}
.pos-rel {
position: relative;;
}
</style>
<script src="../js/zepto.js"></script>
</head>
<body>
<input class="input" type="text" />
<input class="input" type="text" />
<input class="input" type="text" /> <div class="next">
下一步
</div>
</body>
<script>
var isIOS = (/iphone|ipad/gi).test(navigator.appVersion); var likeFixed = function() {
//解绑resize事件 以免进入死循环
$(window).unbind('resize', likeFixed); var t = document.documentElement.scrollTop || document.body.scrollTop, fixed_height = 44, top; //网页可见高度加上滚动条高度 - fixed元素的高度
top = window.innerHeight+ t - fixed_height;
//设置fixed div的top
$('.next').css({'top': top+'px' }); //重新绑定resize事件
setTimeout(function() {
$(window).bind('resize', likeFixed);
}, 10);
} $(function() {
if (isIOS) {
likeFixed();
function touchstart(event) {
$('.next').css('opacity',0);
}
function touchend(event) {
$('.next').css('opacity',1);
}
//touch的时候隐藏
document.addEventListener("touchstart", touchstart, false);
//滚动后重新设置fixed div的位置
window.onscroll = likeFixed;
//touch后显示
document.addEventListener("touchend", touchend, false);
} //所有input blur时重新计算位置,兼容chrome
$('body').on('focusout', 'input', likeFixed);
}); </script>
</html>

解决IOS下不支持fixed的问题的更多相关文章

  1. web页面在ios下不支持fixed可用absolute替代的方案

    本文引用出处:http://www.cnblogs.com/PeunZhang/p/3553020.html. 对于 ios4 和 android2.2 以下不支持 position:fixed 的问 ...

  2. 解决ios下audio不能正常播放的问题

    解决ios下audio不能正常播放的问题 ios系统下会自动屏蔽audio标签的自动播放,需要使用一个事件来驱动音频播放 this.$refs.startaudio.addEventListener( ...

  3. 解决ios下部分手机在input设置为readonly属性时,依然显示光标

    解决ios下部分手机在input设置为readonly属性时,依然显示光标 在出现如上所说的问题是尝试给input 加上  onfocus="this.blur()"  方法 添加 ...

  4. ios下,对于position:fixed支持不完美的额解决方案

    ios下,当有文本框时,会调用输入法,而这个时候,定位(fixed)在底部的东西,就会被弹上例,离底部有段距离,这算是个坑了. 我的解决方案是这样的. 除了定位在底部的元素外,用一个大div把其他元素 ...

  5. 解决ios下的微信打开的页面背景音乐无法自动播放

    后面的项目发现,还有两个坑,需要注意下: ·本文的解决方案的核心是利用了 微信/易信 在ready的时候会有个 WeixinJSBridgeReady/YixinJSBridgeReady事件,通过监 ...

  6. 解决ios下的微信页面背景音乐无法自动播放问题

    在做各种html5场景页面的时候,插入背景音乐是一个很普遍的需求,我们都知道,ios下的safari是无法自动播放音乐的,以至于现在行程一种认知,ios是没有办法自动播放媒体资源的,这个认知其实是错误 ...

  7. 解决IE6下不支持 png24的透明图片问题

    常用的两种解决方案: 第一:使用IE滤镜解决 关键代码: css代码  _background:none;_filter:progid:DXImageTransform.Microsoft.Alpha ...

  8. 解决IE6下Position:fixed问题(只用css)

    在IE6.0及以下版本的浏览器里是不支持position:fixed.而在IE7,IE8,firefox,opera,chrome都可以完美的支持此特性的.解决此问题的要点主要有: 1).容器要有一个 ...

  9. 解决ie6下不支持fix属性,模拟固定定位

    <!DOCTYPE HTML> <html> <head> <meta http-equiv="Content-Type" content ...

随机推荐

  1. hdu1038

    #include <stdio.h> #define P 3.1415927 #define toFeet(x) x/12.0 #define toMiles(x) x/5280.0 in ...

  2. Spring MVC 返回json数据 报406错误 问题解决方案

    将jackson jar包改为jackson-databind-2.5.0.jar  jackson-core-2.5.0.jar  jackson-annotations-2.5.0.jar(这个版 ...

  3. [安全学习环境]Win7 下DVWA安装指南

    一.环境依赖: .Net Framework 3.5 PHP+MySQL 集成测试环境:XAMPP V3.2.1 二.环境准备 1.下载XAMPP(http://www.wampserver.com/ ...

  4. 面试经典——从输入 URL 到页面加载完的过程中都发生了什么事情?

    想要更加了解http协议,猛戳这里 1)把URL分割成几个部分:协议.网络地址.资源路径.其中网络地址指示该连接网络上哪一台计算机,可以是域名或者IP地址,可以包括端口号:协议是从该计算机获取资源的方 ...

  5. 常用的html标签大全

    html标签大全 一.文字 1.标题文字 <h#>..........</h#> #=1~6:h1为最大字,h6为最小字 2.字体变化 <font>........ ...

  6. MVC之联动学习

    一,数据库表设计 CREATE TABLE [dbo].[HY_Province]( [id] [INT] NOT NULL, [province] [NVARCHAR]() NOT NULL, CO ...

  7. Visual Studio 2010 使用 ankhsvn

    之前用的 Windows XP + Visual Studio 2010 + ankhSvn,其中ankhSvn安装完后直接可用, 后来系统换成Windows10后安装ankhSvn,Extentio ...

  8. java 的对象拷贝(有深浅拷贝两种方式,深拷贝实现的两种方式(逐层实现cloneable接口,序列化的方式来实现))

    Java提高篇--对象克隆(复制)(转自:http://www.cnblogs.com/Qian123/p/5710533.html#_label0)   阅读目录 为什么要克隆? 如何实现克隆 浅克 ...

  9. Regmon7.04绿色版(注册表变动实时监视工具)

    Regmon V7.04 简繁中文绿色版 软件大小: 155KB软件语言: 简体中文运行环境:Win9x/NT/2000/XP/2003/软件类别:国外软件 / 免费版 / 系统其它Regmon Re ...

  10. php笔记(六)PHP类与对象之对象接口

    接口的实现 <?php //interface 关键字用于定义一个接口 interface ICanEat{ //接口里面的方法不需要实现 public function eat($food); ...