resize.js 918 B

1234567891011121314151617181920212223242526272829303132
  1. !(function(win, doc) {
  2. const MOBILE_WIDTH = 710 // 750 refer to Bootstrap's responsive design
  3. function $_getDevice() {
  4. const rectWidth = doc.documentElement.clientWidth
  5. if(rectWidth < MOBILE_WIDTH){
  6. return 'mobile'
  7. }else {
  8. return 'pc'
  9. }
  10. }
  11. function setFontSize(device) {
  12. var docEl = doc.documentElement;
  13. var winWidth = docEl.clientWidth;
  14. console.log("setFontSize===",device);
  15. if(device === 'mobile'){
  16. doc.documentElement.style.fontSize = (winWidth / 750) * 100 + "px";
  17. }else{
  18. doc.documentElement.style.fontSize = 1 + "px";
  19. }
  20. }
  21. var userAgent = navigator.userAgent;
  22. win.addEventListener("resize", function() {
  23. if (navigator.userAgent !== userAgent) {
  24. location.reload();
  25. }
  26. });
  27. var device = $_getDevice()
  28. setFontSize(device);
  29. })(window, document);