浏览器缩放

2020-05-15  本文已影响0人  回忆不死我们不散
<!doctype html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, user-scalable=no, initial-scale=1.0, maximum-scale=1.0, minimum-scale=1.0">
    <meta http-equiv="X-UA-Compatible" content="ie=edge">
    <link href="https://cdn.bootcss.com/bootstrap/4.0.0/css/bootstrap.min.css" rel="stylesheet">
    <script src="https://cdn.bootcss.com/vue/2.5.13/vue.min.js"></script>
    <script src="https://unpkg.com/axios/dist/axios.min.js"></script>
    <title>Document</title>
</head>
<body>
    
    

<script>
//  //获取缩放大小
//  function detectZoom (){ 
//    var ratio = 0,
//      screen = window.screen,
//      ua = navigator.userAgent.toLowerCase();
//   
//     if (window.devicePixelRatio !== undefined) {
//        ratio = window.devicePixelRatio;
//    }
//    else if (~ua.indexOf('msie')) {  
//      if (screen.deviceXDPI && screen.logicalXDPI) {
//        ratio = screen.deviceXDPI / screen.logicalXDPI;
//      }
//    }
//    else if (window.outerWidth !== undefined && window.innerWidth !== undefined) {
//      ratio = window.outerWidth / window.innerWidth;
//    }
//     
//     if (ratio){
//      ratio = Math.round(ratio * 100);
//    }
//     
//     return ratio;
//  };
//  detectZoom();
//  console.log(detectZoom())
//  
//  
//  //获取缩放大小
//  var obj = {'window.devicePixelRatio':window.devicePixelRatio,'screen.deviceXDPI / screen.logicalXDPI':screen.deviceXDPI / screen.logicalXDPI,
//       
//         'window.outerWidth / window.innerWidth':window.outerWidth / window.innerWidth,
//         'document.documentElement.offsetHeight / window.innerHeight':document.documentElement.offsetHeight / window.innerHeight,
//       
//         'window.top.outerWidth / window.top.innerWidth':window.top.outerWidth / window.top.innerWidth}
//                      
//      function print(obj){
//        var s = '';
//        for(var key in obj){
//          s+=key;
//          s+=' : ';
//          s+=obj[key];
//          s+='\n\r'
//        }
//        document.write(s)
//         
//      }
//  print(obj)
//  console.log(print(obj))
//
//
//
//
//  // 放大缩小刷新页面
//  var normalWidth = window.innerWidth;
//  var normalHeight = window.innerHeight;
//  window.onresize = function(){
//      if(normalWidth>window.innerWidth||normalHeight< normalHeight.innerHeight){
//          location.reload();
//      }
//  }
//  //关于js禁止浏览器缩放
//  window.addEventListener('mousewheel', function(event){
//      if (event.ctrlKey === true || event.metaKey) {
//            event.preventDefault();
//      }
//  },{ passive: false});
//  
//  //firefox
//   window.addEventListener('DOMMouseScroll', function(event){
//      if (event.ctrlKey === true || event.metaKey) {
//             event.preventDefault();
//      }
//  },{ passive: false});
//  
//  // 原生js来实现,避免依赖jquery。需要注意的是:addEventListener/DOMContentLoaded在ie中是只支持>=ie9的,一般足够了
//  document.addEventListener('DOMContentLoaded', function (event) {
//      // chrome 浏览器直接加上下面这个样式就行了,但是ff不识别
//      document.body.style.zoom = 'reset';
//      document.addEventListener('keydown', function (event) {
//          if ((event.ctrlKey === true || event.metaKey === true)
//          && (event.which === 61 || event.which === 107
//              || event.which === 173 || event.which === 109
//              || event.which === 187  || event.which === 189))
//              {
//                 event.preventDefault();
//              }
//      }, false);
//      document.addEventListener('mousewheel DOMMouseScroll', function (event) {
//          if (event.ctrlKey === true || event.metaKey) {
//              event.preventDefault();
//          }
//      }, false);
//  }, false);




</script>
</body>

</html> 
上一篇下一篇

猜你喜欢

热点阅读