你想要怎样生活,完全由你自己决定。
有些事情不是看到希望才去坚持,而是坚持了才看得到希望!——送给彷徨不安的孩子们

H5技术干货

meta标签相关知识

H5页面窗口自动调整到设备宽度,并禁止用户缩放页面

<meta name="viewport" content="width=device-width,initial-scale=1.0,minimum-scale=1.0,maximum-scale=1.0,user-scalable=no" />

<meta content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=0" name="viewport">

viewport模板

<!DOCTYPE html>

<html>

<head>

<meta charset="utf-8">

<meta content="width=device-width,initial-scale=1.0,maximum-scale=1.0,user-scalable=no" name="viewport">

<meta content="yes" name="apple-mobile-web-app-capable">

<meta content="black" name="apple-mobile-web-app-status-bar-style">

<meta content="telephone=no" name="format-detection">

<meta content="email=no" name="format-detection">

<title>标题</title>

<link rel="stylesheet" href="index.css">

</head>

<body>

这里开始内容

</body>

</html>

width:viewport的宽度

height:viewport的高度

initial-scale:初始的缩放比例

minimum-scale:允许用户缩放到的最小比例

maximum-scale:允许用户缩放到的最大比例

user-scalable:用户是否可以手动缩放

 

添加智能 App 广告条 Smart App Banner(IOS 6+ Safari)

<meta name="apple-itunes-app" content="app-id=myAppStoreID, affiliate-data=myAffiliateData, app-argument=myURL">

 

IOS中Safari允许全屏浏览:

<meta content="yes" name="apple-mobile-web-app-capable">

 

IOS中Safari设置保存到桌面图标

需要在网站的根目录下存放favicon图标,防止404请求(使用fiddler可以监听到)

<link rel="apple-touch-icon" href="icon.png">

 

百度禁止转码

通过百度手机打开网页时,百度可能会对你的网页进行转码,往你页面贴上它的广告,非常之恶心。不过我们可以通过这个meta标签来禁止它:

<meta http-equiv="Cache-Control" content="no-siteapp" />

百度SiteApp转码声明

 

html里面插入图片,如果想让图片自适应屏幕的小而不是宽高固定不变可以在css代码里加入img

{ height: auto; width: auto\9; width:100%; }

 

设置状态栏的背景颜色(IOS)

设置状态栏的背景颜色,只有在 "apple-mobile-web-app-capable" content="yes" 时生效

<meta name="apple-mobile-web-app-status-bar-style" content="black-translucent" />

content 参数:

default :状态栏背景是白色。

black :状态栏背景是黑色。

black-translucent :状态栏背景是半透明。 如果设置为 default 或 black ,网页内容从状态栏底部开始。 如果设置为 black-translucent ,网页内容充满整个屏幕,顶部会被状态栏遮挡。

 

启用 WebApp 全屏模式(IOS)

当网站添加到主屏幕后再点击进行启动时,可隐藏地址栏(从浏览器跳转或输入链接进入并没有此效果)

<meta name="apple-mobile-web-app-capable" content="yes" />

<meta name="apple-touch-fullscreen" content="yes" />

 

将网站添加到主屏幕快速启动方式,仅针对ios的safari顶端状态条的样式

<meta name="apple-mobile-web-app-status-bar-style" content="black" />

<meta name="apple-mobile-web-app-title" content="标题">

<!-- 可选default、black、black-translucent -->

 

禁止ios 长按时不触发系统的菜单,禁止ios&android长按时下载图片

.css{-webkit-touch-callout: none}

 

 

禁止ios和android用户选中文字

.css{-webkit-user-select:none}

 

ios中Safari顶端状态条样式:

<meta content="black" name="apple-mobile-web-app-status-bar-style">

 

当网站添加到主屏幕快速启动方式,可隐藏地址栏,仅针对ios的safari <meta name="apple-mobile-web-app-capable" content="yes" />

<!-- ios7.0版本以后,safari上已看不到效果 -->

 

关闭iOS键盘首字母自动大写

iOS中,默认情况下键盘是开启首字母大写的功能的,如果启用这个功能,可以这样

<input type="text" autocapitalize="off" />

 

关闭iOS输入自动修正

和英文输入默认自动首字母大写那样,IOS还做了一个功能,默认输入法会开启自动修正输入内容,这样的话,用户经常要操作两次。如果不希望开启此功能,我们可以通过input标签属性来关闭掉:

<input type="text" autocorrect="off" />

==》<input autocapitalize="off"  autocorrect="off" />

 

 

 

 

禁止文本缩放

当移动设备横竖屏切换时,文本的大小会重新计算,进行相应的缩放,当我们不需要这种情况时,可以选择禁止:

html { -webkit-text-size-adjust: 100%; }

需要注意的是,PC端的该属性已经被移除,该属性在移动端要生效,必须设置 `meta viewport’。

 

移动端如何清除输入框内阴影

iOS上,输入框默认有内部阴影,但无法使用 box-shadow 来清除,如果不需要阴影,可以这样关闭:

input, textarea {

    border: 0;

    -webkit-appearance: none;

}

textarea这个标签,具有默认样式

-webkit-appearance: none;   通过这个属性可以取消;

 

忽略页面的数字为电话,忽略email识别

<meta name="format-detection" content="telephone=no, email=no"/>

 

指定下拉刷新获取高度的兼容性,低版本的安卓(小米)不支持touchend事件;我们写在touchmove事件里面;

     var scroll=document.documentElement.scrollTop||document.body.scrollTop;//滚动的距离

     var win=document.documentElement.clientHeight||document.body.clientHeight;//窗口的高度

     var scrollHeight=document.documentElement.scrollHeight||document.body.scrollHeight;//文档总高度

 

快速回弹滚动

我们先来看看回弹滚动在手机浏览器发展的历史:

早期的时候,移动端的浏览器都不支持非body元素的滚动条,所以一般都借助 iScroll;

Android 3.0/iOS解决了非body元素的滚动问题,但滚动条不可见,同时iOS上只能通过2个手指进行滚动;

Android 4.0解决了滚动条不可见及增加了快速回弹滚动效果,不过随后这个特性又被移除;

iOS从5.0开始解决了滚动条不可见及增加了快速回弹滚动效果

iOS上如果你想让一个元素拥有像 Native 的滚动效果,你可以这样做:

    .xxx {

        overflow: auto; /* auto | scroll */

        -webkit-overflow-scrolling: touch;

    }

PS:iScroll用过之后感觉不是很好,有一些诡异的bug,这里推荐另外一个 iDangero Swiper,这个插件集成了滑屏滚动的强大功能(支持3D),而且还有回弹滚动的内置滚动条,官方地址:

iDangero

 

移动端禁止选中内容

如果你不想用户可以选中页面中的内容,那么你可以在css中禁掉:

.user-select-none {

  -webkit-user-select: none;  /* Chrome all / Safari all */

  -moz-user-select: none;     /* Firefox all (移动端不需要) */

  -ms-user-select: none;      /* IE 10+ */      

}

 

重新定义滚动条的样式:

   webkit现在支持拥有overflow属性的区域,列表框,下拉菜单,textarea的滚动条自定义样式。

::-webkit-scrollbar {width: 12px;}定义滚动条的宽度;

::-webkit-scrollbar-track {border-left: 1px solid #ccc;}定义滚动条的背景

::-webkit-scrollbar-thumb {background-color: #ccc;}上下箭头

::-webkit-scrollbar-thumb:hover {}

::-webkit-scrollbar-thumb:active{background-color:#333;}

 

按钮active态:

iOS系统的移动设备中,需要在按钮元素或body/html上绑定一个touchstart事件才能激活:active状态

 

ios android判断;

  if (/(iPhone|iPad|iPod|iOS)/i.test(navigator.userAgent)) {

            //console.log($('.input_pass').css({'font-size':'100%','letter-spacing':'19px','top':'0px'}));

  } else if (/(Android)/i.test(navigator.userAgent)) {

            $('.pwd_outer .input_pass').css({'fontSize':'24px','letter-spacing':'22px'});

  } else {

            //console.log('我是其他');

  };

 

移动端取消touch高亮效果在做移动端页面时,会发现所有a标签在触发点击时或者所有设置了伪类 :active 的元素,默认都会在激活状态时,显示高亮框,如果不想要这个高亮,那么你可以通过css以下方法来禁止:

.xxx {

    -webkit-tap-highlight-color: rgba(0, 0, 0, 0);

}

但这个方法在三星的机子上无效,有一种妥协的方法是把页面非真实跳转链接的a标签换成其它标签,可以解决这个问题。

 

模拟按钮hover效果

移动端触摸按钮的效果,可明示用户有些事情正要发生,是一个比较好体验,但是移动设备中并没有鼠标指针,使用css的hover并不能满足我们的需求,还好国外有个激活css的active效果,代码如下,

<!DOCTYPE html>

<html>

<head>

<meta charset="utf-8">

<meta content="width=device-width,initial-scale=1.0,maximum-scale=1.0,user-scalable=no" name="viewport">

<meta content="yes" name="apple-mobile-web-app-capable">

<meta content="black" name="apple-mobile-web-app-status-bar-style">

<meta content="telephone=no" name="format-detection">

<meta content="email=no" name="format-detection">

<style type="text/css">

a{-webkit-tap-highlight-color: rgba(0,0,0,0);}

.btn-blue{display:block;height:42px;line-height:42px;text-align:center;border-radius:4px;font-size:18px;color:#FFFFFF;}

.btn-blue:active{background-color: #357AE8;}

</style>

</head>

<body>

 

<div class="btn-blue">按钮</div>

 

<script type="text/javascript">

document.addEventListener("touchstart", function(){}, true)

</script>

</body>

</html>

兼容性ios5+、部分android 4+、winphone 8

要做到全兼容的办法,可通过绑定ontouchstart和ontouchend来控制按钮的类名

<!DOCTYPE html>

<html>

<head>

<meta charset="utf-8">

<meta content="width=device-width,initial-scale=1.0,maximum-scale=1.0,user-scalable=no" name="viewport">

<meta content="yes" name="apple-mobile-web-app-capable">

<meta content="black" name="apple-mobile-web-app-status-bar-style">

<meta content="telephone=no" name="format-detection">

<meta content="email=no" name="format-detection">

<style type="text/css">

a{-webkit-tap-highlight-color: rgba(0,0,0,0);}

.btn-blue{display:block;height:42px;line-height:42px;text-align:center;border-radius:4px;font-size:18px;color:#FFFFFF;}

.btn-blue-on{background-color: #357AE8;}

</style>

</head>

<body>

 

<div class="btn-blue">按钮</div>

 

<script type="text/javascript">

var btnBlue = document.querySelector(".btn-blue");

btnBlue.ontouchstart = function(){

    this.className = "btn-blue btn-blue-on"

}

btnBlue.ontouchend = function(){

    this.className = "btn-blue"

}

</script>

</body>

</html>

 

移动端基础框架

zepto.js 语法与jquery几乎一样,会jquery基本会zepto~

iscroll.js 解决页面不支持弹性滚动,不支持fixed引起的问题~ 实现下拉刷新,滑屏,缩放等功能~

underscore.js 该库提供了一整套函数式编程的实用功能,但是没有扩展任何JavaScript内置对象。

fastclick 加快移动端点击响应时间

animate.css CSS3动画效果库

Normalize.css Normalize.css是一种现代的、CSS reset为HTML5准备的优质替代方案

 

滑屏框架

适合上下滑屏、左右滑屏等滑屏切换页面的效果

slip.js

iSlider.js

fullpage.js

swiper

 

如何禁止保存或拷贝图像(IOS)

通常当你在手机或者pad上长按图像 img ,会弹出选项 存储图像 或者 拷贝图像,如果你不想让用户这么操作,那么你可以通过以下方法来禁止:

img { -webkit-touch-callout: none; }

 

如何禁止保存或拷贝图像通常当你在手机或者pad上长按图像 img ,会弹出选项 存储图像 或者 拷贝图像,如果你不想让用户这么操作,那么你可以通过以下方法来禁止:

img {

    -webkit-touch-callout: none;

}

PS:需要注意的是,该方法只在 iOS 上有效。

 

 

解决字体在移动端比例缩小后出现锯齿的问题:

-webkit-font-smoothing: antialiased ;

 

栅格布局:

box-sizing:border-box;可以改变盒子模型的计算方式方便你设置宽进行自适应流式布局

 

input[type=input]{-webkit-appearance:none;}移除ios的样式,但这个属性存在bug,会导致iso无法获取checkbox值,给这个元素重新赋上input[type=checkbox]{-webkit-appearance:checkbox;}就不会报错了。

 

webkit表单输入框placeholder的文字能换行么? ios可以,android不行~

 

 

移动端手机号码识别(IOS)

iOS Safari (其他浏览器和Android均不会)上会对那些看起来像是电话号码的数字处理为电话链接,比如:

7位数字,形如:1234567

带括号及加号的数字,形如:(+86)123456789

双连接线的数字,形如:00-00-00111

11位数字,形如:13800138000

可能还有其他类型的数字也会被识别。我们可以通过如下的meta来关闭电话号码的自动识别:

<meta name="format-detection" content="telephone=no" />

开启电话功能

<a href="tel:123456">123456</a>

开启短信功能: winPhone无效

<a href="sms:123456">123456</a>

 

移除原生控件样式

input,button,textarea{-webkit-appearance:none;}

 

ios系统中元素被触摸时产生的半透明灰色遮罩怎么去掉

ios用户点击一个链接,会出现一个半透明灰色遮罩, 如果想要禁用,可设置-webkit-tap-highlight-color的alpha值为0,也就是属性值的最后一位设置为0就可以去除半透明灰色遮罩

a,button,input,textarea{-webkit-tap-highlight-color: rgba(0,0,0,0)}

 

部分android系统中元素被点击时产生的边框怎么去掉

android用户点击一个链接,会出现一个边框或者半透明灰色遮罩, 不同生产商定义出来额效果不一样,可设置-webkit-tap-highlight-color的alpha值为0去除部分机器自带的效果

a,button,input,textarea{

    -webkit-tap-highlight-color: rgba(0,0,0,0)

    -webkit-user-modify:read-write-plaintext-only;

}

 

 

winphone系统a、input标签被点击时产生的半透明灰色背景怎么去掉

<meta name="msapplication-tap-highlight" content="no">

 

-webkit-user-modify有个副作用,就是输入法不再能够输入多个字符

另外,有些机型去除不了,如小米2

对于按钮类还有个办法,不使用a或者input标签,直接用div标签

 

按钮被按下效果的实现需要给a标签加a:active属性和添加一段空函数

document.body.addEventListener('touchend', function () { });

 

-webkit-border-bottom:none;解决去掉下边框。

 

字体大小尽量使用em或者rem,代替px。

移动端字体单位font-size选择px还是rem

对于只需要适配手机设备,使用px即可

对于需要适配各种移动设备,使用rem,例如只需要适配iPhone和iPad等分辨率差别比较挺大的设备

 

移动端click屏幕产生200-300 ms的延迟响应

移动设备上的web网页是有300ms延迟的,玩玩会造成按钮点击延迟甚至是点击失效。

以下是历史原因:

2007年苹果发布首款iphone上IOS系统搭载的safari为了将适用于PC端上大屏幕的网页能比较好的展示在手机端上,使用了双击缩放(double tap to zoom)的方案,比如你在手机上用浏览器打开一个PC上的网页,你可能在看到页面内容虽然可以撑满整个屏幕,但是字体、图片都很小看不清,此时可以快速双击屏幕上的某一部分,你就能看清该部分放大后的内容,再次双击后能回到原始状态。

双击缩放是指用手指在屏幕上快速点击两次,iOS 自带的 Safari 浏览器会将网页缩放至原始比例。

原因就出在浏览器需要如何判断快速点击上,当用户在屏幕上单击某一个元素时候,例如跳转链接<a href="#"></a>,此处浏览器会先捕获该次单击,但浏览器不能决定用户是单纯要点击链接还是要双击该部分区域进行缩放操作,所以,捕获第一次单击后,浏览器会先Hold一段时间t,如果在t时间区间里用户未进行下一次点击,则浏览器会做单击跳转链接的处理,如果t时间里用户进行了第二次单击操作,则浏览器会禁止跳转,转而进行对该部分区域页面的缩放操作。那么这个时间区间t有多少呢?在IOS safari下,大概为300毫秒。这就是延迟的由来。造成的后果用户纯粹单击页面,页面需要过一段时间才响应,给用户慢体验感觉,对于web开发者来说是,页面js捕获click事件的回调函数处理,需要300ms后才生效,也就间接导致影响其他业务逻辑的处理。

解决方案:

fastclick可以解决在手机上点击事件的300ms延迟

zepto的touch模块,tap事件也是为了解决在click的延迟问题

触摸事件的响应顺序

1、ontouchstart

2、ontouchmove

3、ontouchend

4、onclick

解决300ms延迟的问题,也可以通过绑定ontouchstart事件,加快对事件的响应

 

 

移动端touch事件(区分webkit 和 winphone)

当用户手指放在移动设备在屏幕上滑动会触发的touch事件

以下支持webkit

touchstart——当手指触碰屏幕时候发生。不管当前有多少只手指

touchmove——当手指在屏幕上滑动时连续触发。通常我们再滑屏页面,会调用event的preventDefault()可以阻止默认情况的发生:阻止页面滚动

touchend——当手指离开屏幕时触发

touchcancel——系统停止跟踪触摸时候会触发。例如在触摸过程中突然页面alert()一个提示框,此时会触发该事件,这个事件比较少用

以下支持winphone 8

MSPointerDown——当手指触碰屏幕时候发生。不管当前有多少只手指

MSPointerMove——当手指在屏幕上滑动时连续触发。通常我们再滑屏页面,会调用css的html{-ms-touch-action: none;}可以阻止默认情况的发生:阻止页面滚动

MSPointerUp——当手指离开屏幕时触发

 

click产生200-300 ms的延迟响应:

页面js捕获click事件的回调函数处理,需要300ms后才生效

解决方案:

1、fastclick可以解决在手机上点击事件的300ms延迟

2、zepto的touch模块,tap事件也是为了解决在click的延迟问题

 

取消表单元素在点击态时的边框以及半透明灰色背景

input,textarea,button,a{-webkit-tap-highlight-color:rgba(0,0,0,0);}

 

webkit表单元素的默认外观怎么重置

.css{-webkit-appearance:none;}

 

修改webkit表单输入框placeholder的样式颜色值

input::-webkit-input-placeholder{color:#AAAAAA;}

input:focus::-webkit-input-placeholder{color:#EEEEEE;}

 

移动端定义字体,移动端没有微软雅黑字体

对于网站字体设置

移动端项目:

font-family:Tahoma,Arial,Roboto,”Droid Sans”,”Helvetica Neue”,”Droid Sans Fallback”,”Heiti SC”,sans-self;

移动和pc端项目:

font-family:Tahoma,Arial,Roboto,”Droid Sans”,”Helvetica Neue”,”Droid Sans Fallback”,”Heiti SC”,”Hiragino Sans GB”,Simsun,sans-self;

 

android 上去掉语音输入按钮

input::-webkit-input-speech-button {display: none}

 

忽略android平台中对邮箱地址的识别

<meta name="format-detection" content="email=no" />

移动端邮箱识别(Android)

与电话号码的识别一样,在安卓上会对符合邮箱格式的字符串进行识别,我们可以通过如下的meta来管别邮箱的自动识别:

<meta content="email=no" name="format-detection" />

同样地,我们也可以通过标签属性来开启长按邮箱地址弹出邮件发送的功能:

<a mailto:dooyoe@gmail.com">dooyoe@gmail.com</a>

 

使用流体图片

img{

        max-width:100%;

        widht:auto\9;

        height:auto;

 

不定宽高的水平垂直居中

.xxx{

        position:absolute;

        top:50%;

        left:50%;

        z-index:3;

        -webkit-transform:translate(-50%,-50%);

        border-radius:6px;

        background:#fff;

}

[flexbox版]不定宽高的水平垂直居中

.xx{

        justify-content:center;//子元素水平居中,

        align-items:center;//子元素垂直居中;

        display:-webkit-flex;

}

//单行文本溢出

.xx{

        overflow:hidden;

        white-space:nowrap;

        text-overflow:ellipsis;

}

//多行文本溢出

.xx{

        display:-webkit-box !importmort;

        overflow:hidden;

        text-overflow:ellipsis;

        word-break:break-all;

        -webkit-box-orient:vertical;

        -webkit-line-clamp:2;(数字2表示隐藏两行)

}

 

禁用 radio 和 checkbox 默认样式

select::-ms-expand {

display: none;

}

 

::-ms-expand 适用于表单选择控件下拉箭头的修改,有多个属性值,设置它隐藏 (display:none) 并使用背景图片来修饰可得到我们想要的效果。

 

::-ms-check 适用于表单复选框或单选按钮默认图标的修改,同样有多个属性值,设置它隐藏 (display:none) 并使用背景图片来修饰可得到我们想要的效果。

 

当表单文本输入框输入内容后会显示文本清除按钮,::-ms-clear 适用于该清除按钮的修改,同样设置使它隐藏 (display:none) 并使用背景图片来修饰可得到我们想要的效果。

input[type=text]::-ms-clear,input[type=tel]::-ms-clear,input[type=number]::-ms-clear{

display: none;

}

 

 

禁用PC端表单输入框默认清除按钮

input[type=radio]::-ms-check,input[type=checkbox]::-ms-check{

display: none;

}

 

阻止屏幕旋转时字体自动调整

   html, body, form, fieldset, p, div, h1, h2, h3, h4, h5, h6 {-webkit-text-size-adjust:none;}

 

屏幕旋转的事件和样式

事件

window.orientation,取值:正负90表示横屏模式、0和180表现为竖屏模式;

window.onorientationchange = function(){

    switch(window.orientation){

        case -90:

        case 90:

        alert("横屏:" + window.orientation);

        case 0:

        case 180:

        alert("竖屏:" + window.orientation);

        break;

    }

}

样式

//竖屏时使用的样式

@media all and (orientation:portrait) {

.css{}

}

//横屏时使用的样式

@media all and (orientation:landscape) {

.css{}

}

audio元素和video元素在ios和andriod中无法自动播放

应对方案:触屏即播

 

$('html').one('touchstart',function(){

    audio.play()

})

可参考《无法自动播放的audio元素》

 

摇一摇功能

HTML5 deviceMotion:封装了运动传感器数据的事件,可以获取手机运动状态下的运动加速度等数据。

 

手机拍照和上传图片

<input type="file">的accept 属性

 

<!-- 选择照片 -->

<input type=file accept="image/*">

<!-- 选择视频 -->

<input type=file accept="video/*">

使用总结:

ios 有拍照、录像、选取本地图片功能

部分android只有选取本地图片功能

winphone不支持

input控件默认外观丑陋

 

微信浏览器用户调整字体大小后页面矬了,怎么阻止用户调整原因

anroid侧是复写了layoutinflater 对textview做了统一处理

ios侧是修改了body.style.webkitTextSizeAdjust值

普通解决方案:

android暂无方案

ios使用-webkit-text-size-adjust禁止调整字体大小

body{-webkit-text-size-adjust: 100%!important;}

最好的解决方案:  整个页面用rem或者百分比布局

 

消除transition闪屏

网络都是这么写的,但我并没有测试出来

.css{

-webkit-transform-style: preserve-3d;

-webkit-backface-visibility: hidden;

}

设计高性能CSS3动画的几个要素

尽可能地使用合成属性transform和opacity来设计CSS3动画,不使用position的left和top来定位

利用translate3D开启GPU加速

参考《High Performance Animations》

 

android 2.3 bug

@-webkit-keyframes 需要以0%开始100%结束,0%的百分号不能去掉

after和before伪类无法使用动画

border-radius不支持%单位

translate百分比的写法和scale在一起会导致失效,例如-webkit-transform: translate(-50%,-50%) scale(-0.5, 1)

 

android 4.x bug

三星 Galaxy S4中自带浏览器不支持border-radius缩写

同时设置border-radius和背景色的时候,背景色会溢出到圆角以外部分

部分手机(如三星),a链接支持鼠标:visited事件,也就是说链接访问后文字变为紫色

参考《border-radius 移动之伤》

 

fixed bug

ios下fixed元素容易定位出错,软键盘弹出时,影响fixed元素定位

android下fixed表现要比iOS更好,软键盘弹出时,不会影响fixed元素定位

ios4下不支持position:fixed

 

添加到主屏后的APP图标

指定web app添加到主屏后的图标路径,有两种略微不同的方式:

<!-- 设计原图 -->

<link href="short_cut_114x114.png" rel="apple-touch-icon-precomposed">

<!-- 添加高光效果 -->

<link href="short_cut_114x114.png" rel="apple-touch-icon">

apple-touch-icon:在IOS6及以下的版本会自动为图标添加一层高光效果(IOS7开始已使用扁平化的设计风格)

apple-touch-icon-precomposed:使用“设计原图图标”

效果:

 

图标尺寸:

可通过指定size属性来为不同的设备提供不同的图标(但通常来说,我们只需提供一个114 x 114 pixels大小的图标即可 )

官方说明如下

Create different sizes of your app icon for different devices. If you’re creating a universal app, you need to supply app icons in all four sizes.

For iPhone and iPod touch both of these sizes are required:

57 x 57 pixels

114 x 114 pixels (high resolution)

For iPad, both of these sizes are required:

72 x 72 pixels

144 x 144 (high resolution)

 

IOS Web app启动动画

由于iPad 的启动画面是不包括状态栏区域的。所以启动图片需要减去状态栏区域所对应的方向上的20px大小,相应地在retina设备上要减去40px的大小

<!-- iPhone -->

<link href="apple-touch-startup-image-320x460.png" media="(device-width: 320px)" rel="apple-touch-startup-image">

<!-- iPhone (Retina) -->

<link href="apple-touch-startup-image-640x960.png" media="(device-width: 320px) and (-webkit-device-pixel-ratio: 2)" rel="apple-touch-startup-image">

<!-- iPad (portrait) -->

<link href="apple-touch-startup-image-768x1004.png" media="(device-width: 768px) and (orientation: portrait)" rel="apple-touch-startup-image">

<!-- iPad (landscape) -->

<link href="apple-touch-startup-image-748x1024.png" media="(device-width: 768px) and (orientation: landscape)" rel="apple-touch-startup-image">

<!-- iPad (Retina, portrait) -->

<link href="apple-touch-startup-image-1536x2008.png" media="(device-width: 1536px) and (orientation: portrait) and (-webkit-device-pixel-ratio: 2)" rel="apple-touch-startup-image">

<!-- iPad (Retina, landscape) -->

<link href="apple-touch-startup-image-2048x1496.png" media="(device-width: 1536px)  and (orientation: landscape) and (-webkit-device-pixel-ratio: 2)" rel="apple-touch-startup-image">

landscape:横屏 | portrait:竖屏)

 

开启硬件加速

解决页面闪白

保证动画流畅

.css {

   -webkit-transform: translate3d(0, 0, 0);

   -moz-transform: translate3d(0, 0, 0);

   -ms-transform: translate3d(0, 0, 0);

   transform: translate3d(0, 0, 0);

}

 

 

一像素边框

.xx li + li:bofore{

        position:absolute;

        top:-1px;

        left:0px;

        content:' ';

        width:100%;

        height:1px;

        border-top:1px solid #ddd;

        -webkti-transform:scaleY(0.5);

}

 

针对适配等比缩放的方法:

@media only screen and (min-width: 1024px){

        body{zoom:3.2;}

}

@media only screen and (min-width: 768px) and (max-width: 1023px) {

        body{zoom:2.4;}

}

@media only screen and (min-width: 640px) and (max-width: 767px) {

        body{zoom:2;}

}

@media only screen and (min-width: 540px) and (max-width: 639px) {

        body{zoom:1.68;}

}

@media only screen and (min-width: 480px) and (max-width: 539px) {

        body{zoom:1.5;}

}

@media only screen and (min-width: 414px) and (max-width: 479px) {

        body{zoom:1.29;}

}

@media only screen and (min-width: 400px) and (max-width: 413px) {

    body{zoom:1.25;}

}

@media only screen and (min-width: 375px) and (max-width: 413px) {

        body{zoom:1.17;}

}

@media only screen and (min-width: 360px) and (max-width:374px) {

        body{zoom:1.125;}

}

 

使用rem来做响应式开发

针对不同的设备,对页面rem做不同的缩放

html{

font-size:$baseFontSize;

@media screen and(min-width:320px){

font-size:$baseFontSize*.9;

}

@media screen and(min-width:360px){

font-size:$baseFontSize;

}

@media screen and(min-width:400px){

font-size:$baseFontSize*1.1;

}

}

 

rem配置参考:

 

html {font-size:10px}

 

@media screen and (min-width:480px) and (max-width:639px) {

    html {

        font-size: 15px

    }

}

 

@media screen and (min-width:640px) and (max-width:719px) {

    html {

        font-size: 20px

    }

}

 

@media screen and (min-width:720px) and (max-width:749px) {

    html {

        font-size: 22.5px

    }

}

 

@media screen and (min-width:750px) and (max-width:799px) {

    html {

        font-size: 23.5px

    }

}

 

@media screen and (min-width:800px) and (max-width:959px) {

    html {

        font-size: 25px

    }

}

 

@media screen and (min-width:960px) and (max-width:1079px) {

    html {

        font-size: 30px

    }

}

 

@media screen and (min-width:1080px) {

    html {

        font-size: 32px

    }

}

 

 

常用公用CSS style

 

 

 

.clear { zoom:1; }

.clear:after { content:''; display:block; clear:both; }

 

.boxSiz{

    -webkit-box-sizing: border-box;

    -moz-box-sizing: border-box;

    -ms-box-sizing: border-box;

    -o-box-sizing: border-box;

    box-sizing: border-box;

}

.toWrap{

    word-break: break-all;       

    word-wrap: break-word;      

    white-space: pre-wrap;     

}

.noWrap{

    white-space:nowrap;

}

.noWrapEllipsis{

     white-space:nowrap; overflow:hidden; text-overflow:ellipsis;

}

.text-justify{

    text-align:justify;

    text-justify:inter-ideograph;

}

.XX{

    over-flow:hidden;

    white-space:nowrap;

    text-overflow:ellipsis;

}

.XX{

    display:-webkit-box !importmort;

    over-flow:hidden;

    white-space:nowrap;

    text-overflow:ellipsis;

    word-break:break-all;

    -webkit-box-orient:vertical;

    -webkit-line-clamp:2;//这里的2指的是行数

}

 

.flex-center{

    display: -webkit-box;

    display: -moz-box;

    display: -ms-flexbox;

    display: -o-box;

    display: box;

 

 

    -webkit-box-pack: center;

    -moz-box-pack: center;

    -ms-flex-pack: center;

    -o-box-pack: center;

    box-pack: center;

 

    -webkit-box-align: center;

    -moz-box-align: center;

    -ms-flex-align: center;

    -o-box-align: center;

    box-align: center;

}

posted on 2017-12-19 11:13  就酱样Y  阅读(373)  评论(0编辑  收藏  举报