移动端始终横屏及rem 适配
来源:互联网 发布:中森茗苑网易房产数据 编辑:程序博客网 时间:2024/06/06 08:38
这几天做一个项目需要始终横屏,然而找了许多资料,看到H5网页感觉并不能直接控制始终横屏,而是需要使用css3配合JS控制横屏,后面因为适配原因用到rem,于是为了方便和学习,在这结合资料记一个学习笔记。
下面上demo:
css代码:
html{color:#000;background:#FFF}body,div,dl,dt,dd,ul,ol,li,h1,h2,h3,h4,h5,h6,pre,code,form,fieldset,legend,input,textarea,p,blockquote,th,td{margin:0;padding:0}table{border-collapse:collapse;border-spacing:0}fieldset,img{border:0}address,caption,cite,code,dfn,em,strong,th,var{font-style:normal;font-weight:normal}ol,ul{list-style:none}caption,th{text-align:left}h1,h2,h3,h4,h5,h6{font-size:100%;font-weight:normal}q:before,q:after{content:''}abbr,acronym{border:0;font-variant:normal}sup{vertical-align:text-top}sub{vertical-align:text-bottom}input,textarea,select{font-family:inherit;font-size:inherit;font-weight:inherit;*font-size:100%}legend{color:#000}#yui3-css-stamp.cssreset{display:none}html{-webkit-tap-highlight-color:rgba(255,255,255,0);-webkit-appearance:none;-webkit-transform:translate3d(0, 0, 0);}img{ width: 100%; display: block;}/* main css */body{ width: 100%; height: 100%; position: relative; left:0; top: 0; background: #000; overflow: hidden;}#wrap{ height: 100%; position: absolute; left: 50%; top:50%; overflow: hidden;}.content{ width: 1000px; height: 640px; color: #000; position: absolute; left:50%; top:50%;}.pageWrap{ width: 100%; height: 100%; position: absolute; overflow: hidden; left: 0; top:0;transform: translate3d(100%, 0, 0); -webkit-transform: translate3d(100%, 0, 0);}.pageWrap{ background: #42a8fe url(../img/mzBg.png) no-repeat center bottom; background-size:cover; transform: translate3d(0, 0, 0); -webkit-transform: translate3d(0, 0, 0);}
html代码:
横屏测试 html{font-size: 100px;}body{font-size: 0.28rem;}测试的内容11111111111
js代码:
1.横屏
var wrap = $('#wrap');var ww = window.innerWidth;var wh = window.innerHeight;var sec = $('.pageWrap'),canswipe = ww*0.1,hadDown = false;$('body').css({'width':ww+'px','height':wh+'px'});changeScene();window.onresize = function(){canswipe = ww*0.1;//调整画布的位置和大小changeScene();}function changeScene(){var iniW = 1000,iniH = 640,tarW = 0,tarH = 0;ww = window.innerWidth;wh = window.innerHeight;if(ww > wh){//如果浏览器的宽度大于高度,说明是横屏的,画布的宽度 == 浏览器的宽度console.log('浏览器的宽度大于高度');tarW = ww;tarH = tarW*iniH/iniW;$('body').css({'width':ww+'px','height':wh+'px'});wrap.css({'width':ww + 'px','height':wh + 'px','transform':'translate3d(-50%,-50%,0)','-webkit-transform':'translate3d(-50%,-50%,0)'});}else if(ww <= wh){//如果浏览器的宽度小于高度,说明是竖的,画布的宽度 == 浏览器的高度console.log('浏览器的宽度小于高度');tarW = wh;tarH = tarW*iniH/iniW;$('body').css({'width':ww+'px','height':wh+'px'});wrap.css({'width':wh + 'px','height':ww + 'px','transform':'translate3d(-50%,-50%,0) rotate(90deg)','-webkit-transform':'translate3d(-50%,-50%,0) rotate(90deg)'});}}
2.rem适配
(function (doc, win) {var docEl = doc.documentElement, resizeEvt = 'orientationchange' in window ? 'orientationchange' : 'resize', recalc = function () { if(docEl.clientWidth>docEl.clientHeight){ var clientWidth = docEl.clientHeight; }else{ var clientWidth = docEl.clientWidth; }// var clientWidth = docEl.clientWidth; if (!clientWidth) return; docEl.style.fontSize = 100 * (clientWidth / 750) + 'px'; };if (!doc.addEventListener) return;win.addEventListener(resizeEvt, recalc, false);doc.addEventListener('DOMContentLoaded', recalc, false);})(document, window);
以上就是这些内容了。
阅读全文
0 0
- 移动端始终横屏及rem 适配
- 移动端rem及em
- 移动端 rem 适配
- 移动端rem适配
- 移动端自适应rem
- 移动端rem布局
- 移动端 rem
- 移动端rem设置
- 移动端 单位 rem
- 移动端rem布局
- 移动端rem单位
- 移动端 rem 处理
- 移动端rem布局
- 移动端-rem使用
- 移动端rem 解决方案
- 移动端REM响应式模板及相应规范
- js动态计算移动端rem(移动端适配rem)
- 移动端字体大小单位rem
- POJ 1637 浅谈混合图欧拉回路网络流建模
- 《剑指offer》整数中1出现的次数(从1到n整数中1出现的次数)
- java学习笔记六
- 配置_配置WebStatFilter
- 你想拥有开挂的人生吗?
- 移动端始终横屏及rem 适配
- python爬虫-urllib库学习
- android 计时器或倒计时
- Android异步消息处理机制完全解析,带你从源码的角度彻底理解
- 最大连续子序列
- Sevlet的生命周期
- Spring boot快速搭建
- objc[20556]:Class JavaLaunchHelper is implemented in both xxx 警告处理
- c++ new delete知识总结