a78bc17acfdb989195156d1b7154ce3bec6790e7.svn-base 1.4 KB

1234567891011121314151617181920212223242526272829303132333435363738
  1. export default /**
  2. * YDUI 可伸缩布局方案
  3. * rem计算方式:设计图尺寸px / 100 = 实际rem 【例: 100px = 1rem,32px = .32rem】
  4. */
  5. !function (window) {
  6. /* 设计图文档宽度 */
  7. var docWidth = 750;
  8. var doc = window.document,
  9. docEl = doc.documentElement,
  10. resizeEvt = 'orientationchange' in window ? 'orientationchange' : 'resize';
  11. var recalc = (function refreshRem () {
  12. var clientWidth = docEl.getBoundingClientRect().width;
  13. /* 8.55:小于320px不再缩小,11.2:大于420px不再放大 */
  14. docEl.style.fontSize = Math.max(Math.min(20 * (clientWidth / docWidth), 11.2), 8.55) * 5 + 'px';
  15. return refreshRem;
  16. })();
  17. /* 添加倍屏标识,安卓为1 */
  18. docEl.setAttribute('data-dpr', window.navigator.appVersion.match(/iphone/gi) ? window.devicePixelRatio : 1);
  19. if (/iP(hone|od|ad)/.test(window.navigator.userAgent)) {
  20. /* 添加IOS标识 */
  21. doc.documentElement.classList.add('ios');
  22. /* IOS8以上给html添加hairline样式,以便特殊处理 */
  23. if (parseInt(window.navigator.appVersion.match(/OS (\d+)_(\d+)_?(\d+)?/)[1], 10) >= 8)
  24. doc.documentElement.classList.add('hairline');
  25. }
  26. if (!doc.addEventListener) return;
  27. window.addEventListener(resizeEvt, recalc, false);
  28. doc.addEventListener('DOMContentLoaded', recalc, false);
  29. }(window);