移动平台网页开发笔记

 1、限制网页最小宽度,使用缩放手势不能再把界面缩小。
<meta name="viewport" content="width=device-width, initial-scale=1.0" />

如果要完全禁止页面的缩放

<meta name="viewport" content="user-scalable=no, width=device-width" />


2、根据不同宽度调用不同的CSS。 

<link rel="stylesheet" type="text/css" href="test.css" media="only screen and (max-width: 480px)" />
<link rel="stylesheet" type="text/css" href="test2.css" media="screen and (min-width: 481px)" />

第一段表示为宽度<=480时,调用的CSS

第二段表示为宽度>=481时,调用的CSS

以I9100为例,竖屏时调用第一段CSS,横屏时调用第二段CSS,经测试,似乎2段CSS并不是预先加载,也就是说翻转手机后,可能一段时间内仍然是旧的CSS,载入完成后才换过去。

也可以写在style里

<style type="text/css" media="only screen and (max-width: 480px)">
body{ background:#090;}
</style>
<style type="text/css" media="screen and (min-width: 481px)">
body{ background:#960;}
</style>


 

 3、试验ontouchstart ontouchmove ontouchend,写一个拖动的小东西

<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8" />
<meta name="viewport" content="width=device-width; initial-scale=1.0;" />
</head>
<body>
<div id="haha" style="width:300px; height:300px; background:#666; position:absolute; left:0; top:0;">
	asdfas
</div>
<input type="number" id="x" style="position:absolute; left:0; top:400px;" />
<input type="number" id="y" style="position:absolute; left:0; top:450px;" />
</body>
</html>
~function(){
	var _=this, dom = document.getElementById("haha"), x=document.getElementById("x"), y=document.getElementById("y"), dom_loc=[], e_loc=[];
	_.start_touch = function(e){
		var touches = e.touches[0];
		dom_loc = [dom.offsetLeft, dom.offsetTop];
		e_loc = [touches.clientX, touches.clientY];
		x.value = e_loc[0];
		y.value = e_loc[1];
		document.addEventListener("touchmove", _.move_touch, false);
		document.addEventListener("touchend", _.end_touch, false);
		e.preventDefault();
	};
	_.move_touch = function(e){
		var touches = e.touches[0], now_loc = [touches.clientX, touches.clientY];
		dom.style.left = now_loc[0] - e_loc[0] +dom_loc[0] + "px";
		dom.style.top = now_loc[1] - e_loc[1] +dom_loc[1] + "px";
		e.preventDefault();
	};
	_.end_touch = function(e){
		document.removeEventListener("touchmove", _.move_touch, false);
		document.removeEventListener("touchend", _.end_touch, false);
		e.preventDefault();
	};
	dom.addEventListener("touchstart", _.start_touch, false);
}();


 

 

 

 

 

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值