- $(Windows).resize(function ()
- // 绑定到窗口的这个事件中
- {
- var whdef = 100/1920;
- // 表示 1920 的设计图, 使用 100PX 的默认值
- var
- wH = Windows.innerHeight;
- // 当前窗口的高度
- var
- wW = Windows.innerWidth;
- // 当前窗口的宽度
- var rem = wW * whdef;
- // 以默认比例值乘以当前窗口宽度, 得到该宽度下的相应 FONT-SIZE 值
- $('html').CSS('font-size', rem +"px");
- });
- $(function(){
- var whdef = 50/750;
- // 表示 750 的设计图, 使用 50PX 的默认值
- var
- wH = Windows.innerHeight;
- // 手机窗口的高度
- var
- wW = Windows.innerWidth;
- // 手机窗口的宽度
- var rem = wW * whdef;
- // 以默认比例值乘以当前窗口宽度, 得到该宽度下的相应 FONT-SIZE 值
- $('html').CSS('font-size', rem +"px");
- })
- //REM 适配
- var _self = this ;
- _self.width = 750;
- _self.fontSize = 100;
- _self.widthProportion = function (){ var p = (document.body&&document.body.clientWidth||document.getElementsByTagName("html")[0].offsetWidth)/_self.width;return p>1?1:p<0.5?0.5:p;};
- _self.changePage = function (){
- document.getElementsByTagName("html")[0].setAttribute("style","font-size:"+_self.widthProportion()*_self.fontSize+"px !important");
- }
- _self.changePage();
- Windows.addEventListener('resize', function (){_self.changePage();}, false );
来源: http://www.bubuko.com/infodetail-2848929.html