Advertisement
Guest User

Untitled

a guest
Aug 23rd, 2019
93
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.69 KB | None | 0 0
  1. (function (designWidth = 20 / 375) {
  2.  
  3. const docEle: HTMLElement = document.documentElement;
  4. const resizeEvt: string = "orientationchange" in window ? "orientationchange" : "resize";
  5.  
  6. const recalc: EventListener = () => {
  7. const fontSize = Math.floor(docEle.clientWidth * designWidth);
  8. docEle.style.fontSize = fontSize + "px";
  9. const localFontSize = parseInt(window.getComputedStyle(docEle).getPropertyValue('font-size'));
  10. docEle.style.fontSize = fontSize * (fontSize / localFontSize) + "px";
  11. };
  12.  
  13. on('DOMContentLoaded', recalc, document);
  14. on(resizeEvt, recalc);
  15. on('unload', () => { off('DOMContentLoaded', recalc); off(resizeEvt, recalc); })
  16. })()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement