1(function(window, document) { 2 3 'use strict'; 4 5 //ç»hotcsså¼è¾ä¸ªå½å空é´ï¼å«é®æä¸ºä»ä¹ï¼æè¦ç»ä½ åå¤ä½ ä¼ç¨å°çæ¹æ³ï¼å å¾ç¨å°çæ¶åè¿è¦èªå·±åã 6 var hotcss = {}; 7 8 (function() { 9 //æ ¹æ®devicePixelRatioèªå®è®¡ç®scale 10 //å¯ä»¥ææè§£å³ç§»å¨ç«¯1pxè¿ä¸ªä¸çºªé¾é¢ã 11 var viewportEl = document.querySelector('meta[name="viewport"]'), 12 hotcssEl = document.querySelector('meta[name="hotcss"]'), 13 dpr = window.devicePixelRatio || 1, 14 maxWidth = 750, //æå¤§æ¾ç¤ºå°ºå¯¸ 15 designWidth = 0; 16 17 dpr = dpr >= 3 ? 3 : (dpr >= 2 ? 2 : 1); 18 19 //å 许éè¿èªå®ä¹name为hotcssçmeta头ï¼éè¿initial-dpræ¥å¼ºå¶å®ä¹é¡µé¢ç¼©æ¾ 20 if (hotcssEl) { 21 var hotcssCon = hotcssEl.getAttribute('content'); 22 if (hotcssCon) { 23 var initialDprMatch = hotcssCon.match(/initial\-dpr=([\d\.]+)/); 24 if (initialDprMatch) { 25 dpr = parseFloat(initialDprMatch[1]); 26 } 27 var maxWidthMatch = hotcssCon.match(/max\-width=([\d\.]+)/); 28 if (maxWidthMatch) { 29 maxWidth = parseFloat(maxWidthMatch[1]); 30 } 31 var designWidthMatch = hotcssCon.match(/design\-width=([\d\.]+)/); 32 if (designWidthMatch) { 33 designWidth = parseFloat(designWidthMatch[1]); 34 } 35 } 36 } 37 38 document.documentElement.setAttribute('data-dpr', dpr); 39 hotcss.dpr = dpr; 40 41 document.documentElement.setAttribute('max-width', maxWidth); 42 hotcss.maxWidth = maxWidth; 43 44 if (designWidth) { 45 document.documentElement.setAttribute('design-width', designWidth); 46 hotcss.designWidth = designWidth; 47 } 48 49 var scale = 1 / dpr, 50 content = 'width=device-width, initial-scale=' + scale + ', minimum-scale=' + scale + ', maximum-scale=' + scale + 51 ', user-scalable=no'; 52 53 if (viewportEl) { 54 viewportEl.setAttribute('content', content); 55 } else { 56 viewportEl = document.createElement('meta'); 57 viewportEl.setAttribute('name', 'viewport'); 58 viewportEl.setAttribute('content', content); 59 document.head.appendChild(viewportEl); 60 } 61 62 })(); 63 64 hotcss.px2rem = function(px, designWidth) { 65 //é¢å¤ä½ å°ä¼å¨JSä¸ç¨å°å°ºå¯¸ï¼ç¹æä¾ä¸ä¸ªæ¹æ³å©ä½ å¨JSä¸å°px转为remãå°±æ¯è¿ä¹è´´å¿ã 66 if (!designWidth) { 67 //å¦æä½ å¨JSä¸å¤§éç¨å°æ¤æ¹æ³ï¼å»ºè®®ç´æ¥å®ä¹ hotcss.designWidth æ¥å®ä¹è®¾è®¡å¾å°ºå¯¸; 68 //å¦åå¯ä»¥å¨ç¬¬äºä¸ªåæ°åè¯æä½ çè®¾è®¡å¾æ¯å¤å¤§ã 69 designWidth = parseInt(hotcss.designWidth, 10); 70 } 71 72 return parseInt(px, 10) * 750 / designWidth / 100; 73 } 74 75 hotcss.rem2px = function(rem, designWidth) { 76 //æ°å¢ä¸ä¸ªrem2pxçæ¹æ³ãç¨æ³åpx2remä¸è´ã 77 if (!designWidth) { 78 designWidth = parseInt(hotcss.designWidth, 10); 79 } 80 //remå¯è½ä¸ºå°æ°ï¼è¿éä¸ååå¤çäº 81 return rem * 100 * designWidth / 750; 82 } 83 84 hotcss.mresize = function() { 85 //对ï¼è¿ä¸ªå°±æ¯æ ¸å¿æ¹æ³äºï¼ç»HTML设置font-sizeã 86 var innerWidth = document.documentElement.getBoundingClientRect().width || window.innerWidth; 87 88 if (hotcss.maxWidth && (innerWidth / hotcss.dpr > hotcss.maxWidth)) { 89 innerWidth = hotcss.maxWidth * hotcss.dpr; 90 } 91 92 if (!innerWidth) { 93 return false; 94 } 95 96 document.documentElement.style.fontSize = (innerWidth * 100 / 750) + 'px'; //设计尺寸750 æ ¹å ç´ ä¸º100px 便äºè®¡ç® 97 98 hotcss.callback && hotcss.callback(); 99 100 }; 101 102 hotcss.mresize(); 103 //ç´æ¥è°ç¨ä¸æ¬¡ 104 105 window.addEventListener('resize', function() { 106 clearTimeout(hotcss.tid); 107 hotcss.tid = setTimeout(hotcss.mresize, 33); 108 }, false); 109 //ç»å®resizeçæ¶åè°ç¨ 110 111 window.addEventListener('load', hotcss.mresize, false); 112 //鲿¢ä¸æåå çbugãloadä¹ååè°ç¨ä¸æ¬¡ã 113 114 115 setTimeout(function() { 116 hotcss.mresize(); 117 //鲿¢æäºæºåæªå¼ç°è±¡ï¼å¼æ¥åè°ç¨ä¸æ¬¡ 118 }, 333) 119 120 window.hotcss = hotcss; 121 //å½åç©ºé´æ´é²ç»ä½ ï¼æ§å¶æäº¤ç»ä½ ï¼æ³æä¹è°æä¹è°ã 122 123 124})(window, document);
Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.