国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁(yè) > 編程 > JavaScript > 正文

移動(dòng)適配的幾種方案(三種方案)

2019-11-19 18:49:39
字體:
來(lái)源:轉(zhuǎn)載
供稿:網(wǎng)友

1.直接利用js適配

(function (doc, win) {var docEl = doc.documentElement,resizeEvt = 'orientationchange' in window ? 'orientationchange' : 'resize',recalc = function () {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);

例如:100px=1rem;10px=0.1rem;1px=0.01rem;

2.利用js+less適配

(function (win) {function setUnitA() {document.documentElement.style.fontSize = document.documentElement.clientWidth / 10 + "px";}var h = null;window.addEventListener("resize", function () { clearTimeout(h); h = setTimeout(setUnitA, 300); }, false);setUnitA();})(window);

less:文件頂部定義@unit: 750/10rem,然后css全文件的單位直接用@unit。

例如:100px=100/@unit;10px=10/@unit;1px=1/@unit;

3.利用less適配。

html {font-size: 20px;}@media only screen and (min-width: 401px) {html {font-size: 25px !important;}}@media only screen and (min-width: 428px) {html {font-size: 26.75px !important;}}@media only screen and (min-width: 481px) {html {font-size: 30px !important;}}@media only screen and (min-width: 569px) {html {font-size: 35px !important;}}@media only screen and (min-width: 641px) {html {font-size: 40px !important;}}@unit: 40rem;

例如:100px=100/@unit;10px=10/@unit;1px=1/@unit;

以上所述是小編給大家介紹的移動(dòng)適配的幾種方案(三種方案),希望對(duì)大家有所幫助,如果大家有任何疑問(wèn)請(qǐng)給我留言,小編會(huì)及時(shí)回復(fù)大家的。在此也非常感謝大家對(duì)武林網(wǎng)網(wǎng)站的支持!

發(fā)表評(píng)論 共有條評(píng)論
用戶名: 密碼:
驗(yàn)證碼: 匿名發(fā)表
主站蜘蛛池模板: 徐州市| 桐梓县| 合作市| 台东县| 正镶白旗| 莱阳市| 崇明县| 南昌市| 周至县| 德兴市| 武功县| 道真| 忻城县| 日土县| 贵德县| 华阴市| 通辽市| 东丰县| 菏泽市| 余江县| 密云县| 华池县| 项城市| 岢岚县| 积石山| 年辖:市辖区| 湘潭县| 钟祥市| 宝山区| 安化县| 镇雄县| 萨嘎县| 徐水县| 江城| 东乡族自治县| 元谋县| 中宁县| 荣成市| 吴忠市| 汽车| 蒙城县|