首次写iPad布局感想(H5)

一直作前端工做,却历来没有开发过平板的项目,想来也是有遗憾的,孰知,新公司的第二个项目就是要适配平板,刚开始是懵的,对于兼容,感受是本身的短板,但庆幸的是这一版只须要兼容iOS系统就能够。前端

那我如今就说下开发iOS h5项目可能会进到的误区(知道很菜,可是写出来也是对本身加深印象)

- ios的专有metaios

<meta name="apple-mobile-web-app-capable" content="yes" />
<meta name="format-detection" content="telephone=no" />
......列举经常使用,其余用时可百度

不要觉得引入<meta name="viewport" content="target-densitydpi=device-dpi, width=device-width, initial-scale=1, user-scalable=no, minimum-scale=1.0, maximum-scale=1.0">对于禁止屏幕缩放就万事大吉了,这只针对于谷歌浏览器,要想兼容苹果自带的Safari还须要写入下面这段代码web

window.onload=function () {
      document.addEventListener('touchstart',function (event) {
        if(event.touches.length>1){
          event.preventDefault();
        }
      })
      var lastTouchEnd=0;
      document.addEventListener('touchend',function (event) {
        var now=(new Date()).getTime();
        if(now-lastTouchEnd<=300){
          event.preventDefault();
        }
        lastTouchEnd=now;
      },false)
    }

- button、input、textarea触发时的灰色背景块(高亮显示)
这都是须要咱们去禁止的,毕竟要还原设计稿嘛,这是就要加入这几个属性浏览器

-webkit-appearance: none;
  outline: none;
  -webkit-tap-highlight-color: rgb(0, 0, 0, 0);透明度须要为0
  -webkit-user-modify: read-write-plaintext-only;

- 页面滚动效果
若是在须要滚动的区块内添加了overflow: auto;这个样式
确定会发现滚动的效果不是很流畅,这时就须要在body上添加一个样式overflow-x: hidden; 实现方式不止一种 也能够在滚动快上添加webkit-overflow-scrolling: touch;app

相关文章
相关标签/搜索