1.安卓浏览器看背景图片,有些设备会显示模糊
用同等比例的图片在PC机上很清楚,但是手机上很模糊,原因是什么呢?
经过研究,是devicePixelRatio作怪,因为手机分辨率太小,如果按照分辨率来显示网页,这样字会非常小,所以苹果当初就把iPhone 4的960640分辨率,在网页里只显示了480320,这样devicePixelRatio=2。现在android比较乱,有1.5的,有2的也有3的。
想让图片在手机里显示更为清晰,必须使用2x的背景图来代替img标签(一般情况都是用2倍)。
例如一个div的宽高是100100,背景图必须得200200,然后background-size:contain;,这样显示出来的图片就比较清晰了。
指定 background-size:contain;都可以,大家试试!
background:url(../images/icon/all.png) no-repeat center center;
-webkit-background-size:50px 50px;
background-size: 50px 50px;
display:inline-block;
width:100%;
height:50px;
2.图片加载
若您遇到图片加载很慢的问题,对这种情况,手机开发一般用canvas方法加载:
具体的canvas API 参见:http://javascript.ruanyifeng.com/htmlapi/canvas.html
<li><canvas></canvas></li>
tmpl +='<li style="width:'+picWidth+'px;height:'+picWidth+'px;padding-left:'+p+'px;padding-top:'+padding+'px;"><canvas id="cvs_'+i+'"></canvas></li>';
var total=17;
var zWin=$(window);
var render=function(){
var padding=2;
var winWidth=zWin.width();
var picWidth=Math.floor((winWidth-padding*3)/4);
var tmpl ='';
for (var i=1;i<=totla;i++){ var="" p="padding;" imgsrc="img/" +i+'.jpg';="" if(i%4="=1){" }="" tmpl="" +="" ;="" imageobj="new" image();="" imageobj.index="i;" imageobj.onload="function(){" cvs="$('#cvs_'+this.index)[0].getContext('2d');" cvs.width="this.width;" cvs.height="this.height;" cvs.drawimage(this,0,0);="" imageobj.src="imgSrc;" render();="" <="" code="">=totla;i++){>
3.假如手机网站不用兼容IE浏览器,一般我们会使用zeptojs。
zeptojs内置Touch events方法,具体可以看http://zeptojs.com/#Touch events
看了一下zeptio新版的API,已经支持IE10以上浏览器,对zeptojs可以选择使用!
4.防止手机中网页放大和缩小,就是设置meta中的viewport
使用viewport使页面禁止缩放。 通常把user-scalable设置为0来关闭用户对页面视图缩放的行为。
<meta name="viewport" content="user-scalable=0" />
但是为了更好的兼容,我们会使用完整的viewport设置。
<meta name="viewport" content="width=device-width,initial-scale=1.0,maximum-scale=1.0,user-scalable=0" />
当然,user-scalable=0,有的人也写成user-scalable=no,都可以的。
width=device-width 宽度是设备屏幕的宽度(像素)
height=device-height 高度是设备屏幕的高度(像素)
initial-scale 初始的缩放比例
minimum-scale 允许用户缩放到的最小比例
maximum-scale 允许用户缩放到的最大比例
user-scalable 用户是否可以手动缩放
5.apple-mobile-web-app-capable
apple-mobile-web-app-capable是设置Web应用是否以全屏模式运行。1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18说明:
如果content设置为yes,Web应用会以全屏模式运行,反之,则不会。content的默认值是no,表示正常显示。你可以通过只读属性window.navigator.standalone来确定网页是否以全屏模式显示。
兼容性:iOS 2.1 +
### 6.format-detection ###
format-detection 启动或禁用自动识别页面中的电话号码。 以前就是这个造成安卓和ios浏览的不统一;
```<meta name="format-detection" content="telephone=no">```
默认情况下,设备会自动识别任何可能是电话号码的字符串。设置telephone=no可以禁用这项功能。
meta name="format-detection" content="telephone=no"
meta name="format-detection" content="email=no"
meta name="format-detection" content="adress=no"
也可以连写:meta name="format-detection" content="telephone=no,email=no,adress=no"
### 7.html5调用安卓或者ios的拨号功能 ###
html5提供了自动调用拨号的标签,只要在a标签的href中添加tel:就可以了。
```<a href="tel:4008106999,1034">400-810-6999 转 1034</a>```
```<a href="tel:15677776767">点击拨打15677776767</a>
8.获取h5的经纬度
HTML5中的GPS定位之getCurrentPosition,可以查找一下这个进行设置和使用。
9.上下拉动滚动条时卡顿、慢
1 | body { |
- js给doucument绑定touchstart或touchend事件
1 | <style> |
11、圆角bug
某些Android手机圆角失效
background-clip: padding-box;