移动端页面强制横屏

<!DOCTYPE html>
<html>

	<head>
		<meta charset="UTF-8">
		<meta name="viewport" wrapper="width=device-width,initial-scale=1,minimum-scale=1,maximum-scale=1,user-scalable=no" />
		<title></title>
		<style type="text/css">
			* { margin: 0; }
			.wrapper { position: absolute; top: 0; left: 0; width: 100%; overflow-y: scroll; }
			.content{width: 100%;}
			img{width: 100%;}
		</style>
	</head>

	<body>
		<div class="wrapper">
			<div class="content">
				<img src="http://attach.bbs.miui.com/forum/201301/27/132323rsp4ts9jzxpyuf3x.jpg"/>
				<img src="http://attach.bbs.miui.com/forum/201301/27/132323rsp4ts9jzxpyuf3x.jpg"/>
				<img src="http://attach.bbs.miui.com/forum/201301/27/132323rsp4ts9jzxpyuf3x.jpg"/>
				<img src="http://attach.bbs.miui.com/forum/201301/27/132323rsp4ts9jzxpyuf3x.jpg"/>
				<img src="http://attach.bbs.miui.com/forum/201301/27/132323rsp4ts9jzxpyuf3x.jpg"/>
				<img src="http://attach.bbs.miui.com/forum/201301/27/132323rsp4ts9jzxpyuf3x.jpg"/>
			</div>
		</div>
		<script src="js/jquery1.12.4.min.js" type="text/javascript" charset="utf-8"></script>
		<script type="text/javascript">
			$(function() {
				var width = document.documentElement.clientWidth;
				var height = document.documentElement.clientHeight;
				$w = $('.wrapper');
				$w.width(width);
				$w.height(height);

				if(width < height) {
					// 竖屏
					changeToPortrait($w, width, height);
				}

				window.onresize = changeOrientation;
			});

			function changeOrientation() {
				var width = document.documentElement.clientWidth;
				var height = document.documentElement.clientHeight;
				$w = $('.wrapper');
				if(width > height) {
					// 横屏
					changeToLandscape($w, width, height);
				} else {
					// 竖屏
					changeToPortrait($w, width, height);
				}

			}
			// 横屏
			function changeToLandscape($w, width, height){
				$w.width(width);
				$w.height(height);
				$w.css('top', 0);
				$w.css('left', 0);
				$w.css('transform', 'none');
				$w.css('transform-origin', '50% 50%');
			}
			// 竖屏
			function changeToPortrait($w, width, height){
				$w.width(height);
				$w.height(width);
				$w.css('top', (height - width) / 2);
				$w.css('left', 0 - (height - width) / 2);
				$w.css('transform', 'rotate(90deg)');
				$w.css('transform-origin', '50% 50%');
			}
		</script>
	</body>

</html>

 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值