移动端开发仿app头部底部固定设置position:fixed,android2.2以上已经实现。但是在ios8以下系统,当小键盘激活时,都会出现位置浮动问题。如图:

如何解决:

查阅资料之后想到一下几种解决方法

1,使用position:absolute模拟

<script type="text/javascript">
    window.onscroll=function(){
    $(".fixed").css("top",$(window).scrollTop());
   $(".foot").css("top",$(window).scrollTop()+$(window).height());
}
</script>

问题来了:滑动页面时头部底部div会有明显的抖动。

2,判断当前获得焦点元素是input则隐藏div改为position:absolute

<body onload=setInterval("a()",500)>

<script type="text/javascript">
  function a(){
    if(document.activeElement.tagName == 'INPUT'){    
      $(".fixed").css({'position': 'absolute','top':'0'}); 
       } else {  
         $(".fixed").css('position', 'fixed');  
        }
      }
  </script>

问题来了:不停监控dom,消耗资源。如果input个数较少,可在input里面添加onfocus事件好一些。但是如果是底部固定div此方法好像不太给力。

3,插件iscroll.js个人感觉不是很好用。可能方法不对,jQuery Mobile  没尝试,感觉会增负担。

4,重点来了:

只需要在中间部分外层div添加css样式position:fixed;top:50px; bottom:50px;overflow:scroll;就可以实现效果,无需插件。可拷贝下面代码运行。

<!DOCTYPE html>
<html lang="zh_cmn">
<head>
<meta charset=utf-8 />
<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1" />
<meta name="viewport" content="width=device-width, user-scalable=no, initial-scale=1.0, minimum-scale=1.0, maximum-scale=1.0" />
<title></title>
<style>
.head,.foot{position:fixed;left:0;height:38px;line-height:38px;width:100%;background-color:#99CC00;}
.head{top:0;}
.foot{bottom:0;}
.main{position:fixed;top:38px;bottom:38px;width:100%;overflow:scroll;background-color:#BABABA;}
</style>
</head>
<body>
<header class="head">顶部固定区域</header>
<article class="main"  id="wrapper">  
    <div>
     <p>当内容欲出隐藏时,灰色区域可上下拖动</p>
    <p>当内容欲出隐藏时,灰色区域可上下拖动</p>
     <p>当内容欲出隐藏时,灰色区域可上下拖动</p>
     <p>当内容欲出隐藏时,灰色区域可上下拖动</p>
     <p>当内容欲出隐藏时,灰色区域可上下拖动</p>
     <p>当内容欲出隐藏时,灰色区域可上下拖动</p>
     <p>当内容欲出隐藏时,灰色区域可上下拖动</p>
     <p>当内容欲出隐藏时,灰色区域可上下拖动</p>
     <p>当内容欲出隐藏时,灰色区域可上下拖动</p>
     <p>当内容欲出隐藏时,灰色区域可上下拖动</p>
     <p>当内容欲出隐藏时,灰色区域可上下拖动</p>
    <input type="text" value="" class="inputtext"> <br>
        <input type="text" value="" class="inputtext"> <br>
   <input type="text" value="" class="inputtext"> <br>
   <input type="text" value="" class="inputtext"> <br>
     <input type="text" value="" class="inputtext"> <br>
     <input type="text" value="" class="inputtext"> <br>
    <input type="text" value="" class="inputtext"> <br>
    <input type="text" value="" class="inputtext"> <br>
    <input type="text" value="" class="inputtext"> <br>
     <input type="text" value="" class="inputtext"> <br>
     <input type="text" value="" class="inputtext"> <br>
     <input type="text" value="" class="inputtext"> <br>
     <input type="text" value="" class="inputtext"> <br>
     <input type="text" value="" class="inputtext"> <br>
     <input type="text" value="" class="inputtext"> <br>
     <input type="text" value="" class="inputtext"> <br>
     <input type="text" value="" class="inputtext"> <br>
     <input type="text" value="" class="inputtext"> <br>
     <input type="text" value="" class="inputtext"> <br>
   <input type="text" value="" class="inputtext"> <br>
   <input type="text" value="" class="inputtext"> <br>
     <input type="text" value="" class="inputtext"> <br>
     <input type="text" value="" class="inputtext"> <br>
    <input type="text" value="" class="inputtext"> <br>
    <input type="text" value="" class="inputtext"> <br>
   <input type="text" value="" class="inputtext"> <br>
     <input type="text" value="" class="inputtext"> <br>
     <input type="text" value="" class="inputtext"> <br>
    <input type="text" value="" class="inputtext"> <br>
    <input type="text" value="" class="inputtext"> <br>
   <input type="text" value="" class="inputtext"> <br>
  <input type="text" value="" class="inputtext"> <br>
  <input type="text" value="" class="inputtext"> <br>
    <input type="text" value="" class="inputtext"> <br>
   <input type="text" value="" class="inputtext"> <br>
   <input type="text" value="" class="inputtext"> <br>
    <input type="text" value="" class="inputtext"> <br>
    <input type="text" value="" class="inputtext"> <br>
    <input type="text" value="" class="inputtext"> <br>
    <input type="text" value="" class="inputtext"> <br>
    <input type="text" value="" class="inputtext"> <br>
    <input type="text" value="" class="inputtext"> <br>
    <input type="text" value="" class="inputtext"> <br>
     <input type="text" value="" class="inputtext"> <br>
    <input type="text" value="" class="inputtext"> <br>
    <input type="text" value="" class="inputtext"> <br>
     content <br>
    content <br>
    content <br>
    content <br>
    content <br>
    content <br>
    content <br>
    content <br>
    content <br>
  </div>
</article>
<footer class="foot">底部固定区域</footer>
</body>
</html>

当小键盘出现时头部、底部自动跳到页面最顶端、最底端。键盘隐藏时又会固定在头部,底部。顿时感觉开朗了

小技巧css解决移动端ios不兼容position:fixed属性,无需插件的更多相关文章

  1. IOS系统不兼容position: fixed;属性的解决方案

    position: fixed;属性在IOS系统手机上会有很明显的抖动,解决方式: 只需要在中间部分外层div添加css样式position:fixed;top:50px; bottom:50px;o ...

  2. 解决IE6不支持position:fixed属性

    最近在优化网站浮动广告时候遇见了IE6不支持position:fixed属性.上网收集了一下解决方案 比较好的方案就是利用css表达式进行解决 补充:CSS Expression (CSS 表达式), ...

  3. 解决IE6下固定定位问题 使用position:fixed

    IE6浏览器有太多的bug让制作网页的人头疼.这篇文章介绍的是介绍的是如何解决IE6不支持position:fixed;属性的办法. 如果我们需要做某个元素始终位于浏览器的底部,不会因为浏览器窗口的缩 ...

  4. css 兼容 position:fixed

    我是头 我是主体 有多少内容,我就有多高   我是脚 我要随滚动条滚动 我要随滚动条滚动 我要随滚动条滚动 <!DOCTYPE html PUBLIC "-//W3C//DTD XHT ...

  5. 记录一些实用的小技巧-CSS篇

    1.单行文本截断 .text{ width: 200px; text-overflow: ellipsis; white-space: nowrap; overflow: hidden; } 2.多行 ...

  6. 移动端web页面使用position:fixed问题

    在做移动端项目时,碰到一个很纠结的问题,头部固定的问题,一开始使用fixed,发现一系列的问题, 问题1:footer输入框 focus 状态,footer 被居中,而不是吸附在软键盘上部. 测试环境 ...

  7. 移动端采坑:Position: fixed 在Safari上的Bug

    Position: fixed 在IOS上的显示效果 会出现两种情况: 点击fixed定位的元素会出现fixed定位失效导致的元素贴向底部,即position: absolute,bottom: 0p ...

  8. 移动端web页面使用position:fixed问题总结

    近期完成了一个新的项目(搜狐直播),其中又涉及到了 fixed(固定位置定位)的问题,在之前的文章<移动Web产品前端开发口诀——“快”>中已经阐述过我对 iScroll 的态度,所以在这 ...

  9. 父节点使用css的transform: translate(0, 0)时position:fixed在chrome浏览器中无效

    今天在做移动端的页面,无意间发现了一个Chrome浏览器下的一个bug,在使用CSS3的transform: translate(0, 0)属性对节点A进行位置转化,此时A节点下面有一个字节点B,节点 ...

随机推荐

  1. 论C++的发家史以及相对其他语言优缺

    C++发家史: 最初导致C++诞生的原因是在Bjarne博士等人试图去分析UNIX的内核的时候,这项工作开始于1979年4月,当时由于没有合适的工具能够有效的分析由于内核分布而造成的网络流量,以及怎样 ...

  2. VS 2010解决方案添加头文件和动态库

    右键点击项目,选择“properties”, Additional include references:头文件路径,分号隔开. Additional library directories:

  3. java基础基础总结----- 常用DOS命令(一)

    常用DOS命令 dir(directory):列出当前目录下的文件以及文件夹 mkdir (make directory) : 创建目录 rd (remove directory): 删除目录 cd ...

  4. ML面试题网站及ML模型网站

    一.面试题网站 1)最全:http://www.epx365.cn/jyzn/201839501.html 2)七月在线:https://blog.csdn.net/movie14/article/d ...

  5. 读取Easy UI的DATa grid里面的所有数据

    目前我知道的有两种方法: 1.读取行数,循环读出 $("#btnEcxel").click(function () { var rows = $('#tbVehicleList') ...

  6. Codeforces 950 C. Zebras

    http://codeforces.com/contest/950/problem/C 题意: 给出一个01序列,问能否将这个序列分为若干个0开头0结尾的序列 输出方案 如果有解,几个1能在一个序列就 ...

  7. idea常用快捷键及自定义快捷键汇总

    以下都是挨个进行验证过的 生成get和set方法为:alt+insert 自动补全返回值,自动补全变量名称和属性名称:ctrl+alt+v 输入System.out.println()的快捷方法是:输 ...

  8. Spring 学习04

    一.上节内容回顾 1 基于aspectj的注解aop操作 2 spring的jdbcTemplate操作 (1)实现crud操作 - 添加.修改.删除update方法 - 查询 -- 查询某个值 qu ...

  9. CSS魔法(二)

    # 文档类型<!DOCTYPE> <!DOCTYPE html> # 字符集 <meta charset="UTF-8" /> # 换行标签 & ...

  10. FastReport动态绑定只显示一条数据。

    产生这个问题的原因是因为需要把Band绑定DataSource.有两种方法 (1)DataBand data = report1.Report.FindObject("Data1" ...