物管理前端
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

30 lines
858 B

  1. (function (){
  2. var monitorZoom = () => {
  3. let ratio = 0,
  4. screen = window.screen,
  5. ua = navigator.userAgent.toLowerCase();
  6. if (window.devicePixelRatio !== undefined) {
  7. ratio = window.devicePixelRatio;
  8. } else if (~ua.indexOf("msie")) {
  9. if (screen.deviceXDPI && screen.logicalXDPI) {
  10. ratio = screen.deviceXDPI / screen.logicalXDPI;
  11. }
  12. } else if (
  13. window.outerWidth !== undefined &&
  14. window.innerWidth !== undefined
  15. ) {
  16. ratio = window.outerWidth / window.innerWidth;
  17. }
  18. if (ratio) {
  19. ratio = Math.round(ratio * 100);
  20. }
  21. return ratio;
  22. };
  23. var m = monitorZoom();
  24. if (window.screen.width * window.devicePixelRatio >= 3840) {
  25. document.body.style.zoom = 100 / (Number(m) / 2); // 屏幕为 4k 时
  26. } else {
  27. document.body.style.zoom = 100 / Number(m);
  28. }
  29. })()