屏幕适配—在电脑默认推荐缩放比为125%或150%等情况下的浏览器100%显示的适配(适用大数据平台)

屏幕适配—在电脑默认推荐缩放比为125%或150%等情况下的浏览器100%显示的适配(适用大数据平台)

1.创建缩放适配DevicePixelRatio.js文件
在_correct方法中进行限制。

/**
  * @author xingwu
  * @date  2022-06-10
  * @description 校正windows页面在系统进行缩放后导致页面被放大的问题,通常放大比例是125%、150%
  * **/
  class DevicePixelRatio {
    constructor() {
      //this.flag = false;
    }
    //获取系统类型
    _getSystem() {
      let flag = false;
      var agent = navigator.userAgent.toLowerCase();
      //		var isMac = /macintosh|mac os x/i.test(navigator.userAgent);
      //		if(isMac) {
      //			return false;
      //		}
      //现只针对windows处理,其它系统暂无该情况,如有,继续在此添加
      if(agent.indexOf("windows") >= 0) {
        return true;
      }
    }
    //获取页面缩放比例
    //	_getDevicePixelRatio() {
    //		let t = this;
    //	}
    //监听方法兼容写法
    _addHandler(element, type, handler) {
      if(element.addEventListener) {
        element.addEventListener(type, handler, false);
      } else if(element.attachEvent) {
        element.attachEvent("on" + type, handler);
      } else {
        element["on" + type] = handler;
      }
    }
    //校正浏览器缩放比例    在这里进行配置。页面的缩放为多少,及对应的像素下 进行适配。
    _correct() {
      let t = this;
      let width = window.screen.width
      if(width == 1536 && window.devicePixelRatio == 1.25 || width == 1280 && window.devicePixelRatio == 1.5 ){
        document.getElementsByTagName('body')[0].style.zoom = 1 / window.devicePixelRatio;
      }
      //页面devicePixelRatio(设备像素比例)变化后,计算页面body标签zoom修改其大小,来抵消devicePixelRatio带来的变化。
      // document.getElementsByTagName('body')[0].style.zoom = 1 / window.devicePixelRatio;
      console.log(window.devicePixelRatio,width)
    }
    //监听页面缩放
    _watch() {
      let t = this;
      t._addHandler(window, 'resize', function() { //注意这个方法是解决全局有两个window.resize
        //重新校正
        t._correct()
      })
    }
    //初始化页面比例
    init() {
      let t = this;
      if(t._getSystem()) { //判断设备,目前只在windows系统下校正浏览器缩放比例
        //初始化页面校正浏览器缩放比例
        t._correct();
        //开启监听页面缩放
        t._watch();
      }
    }
  }
  export default DevicePixelRatio;    

2.2.在要使用的页面中进行引入:

 import DevicePixelRatio from '../../../../components/DevicePixelRatio.js';//放大缩小适配  

3.在mounted中进行new操作:

mounted() {
    this.$nextTick(()=>{  //这个只是用来调用echarts的,
          this.mapEcharts();
      })
    new DevicePixelRatio().init();//适配放大缩小
  }, 

缺陷:有可能会出现echarts在鼠标hover时,echarts标点偏移。
解决方法:通过媒体查询修改html的样式。将zoom使用transform: scale(0.8)代替;transform-origin: 0px 0px;width: 125%;height: 125%;

@media screen and (max-width: 1280px){
    /* CSS代码 */
    html {
        font-size: 12px !important;
        transform: scale(0.8);
        transform-origin: 0px 0px;
        width: 125%;
        height: 125%;
    }
}
@media screen and (min-width: 1281px) and (max-width: 1365px) {
    /* CSS代码 */
    html {
        font-size: 14px !important;
        transform: scale(0.8);
        transform-origin: 0px 0px;
        width: 125%;
        height: 125%;
    }
    .dataWatsh {
        .service-bottom-box {
            .title {
                padding-top: 1% !important;
            }
        }
    }
 }
@media screen and (min-width: 1366px) and (max-width: 1440px) {
    /* CSS代码 */
    html {
        font-size: 14px !important;
        transform: scale(0.8);
        transform-origin: 0px 0px;
        width: 125%;
        height: 125%;
    }
}
@media screen and (min-width: 1441px) and (max-width: 1500px) {
    /* CSS代码 */
    html {
        font-size: 14px;
        transform: scale(0.8);
        transform-origin: 0px 0px;
        width: 125%;
        height: 125%;
    }
 }
@media screen and (min-width: 1501px) and (max-width: 1536px) {
    /* CSS代码 */
    html {
        font-size: 14px;
        transform: scale(0.8);
        transform-origin: 0px 0px;
        width: 125%;
        height: 125%;
    }
 }
@media screen and (min-width: 1537px) and (max-width: 1919px) {
    /* CSS代码 */
    html {
        font-size: 14px;
        transform: scale(0.8);
        transform-origin: 0px 0px;
        width: 125%;
        height: 125%;
    }
    .delayCount {
        position: relative;
        height: 81% !important;
        margin: 0 !important;
        align-items: center;
    }
 }
 @media screen and (min-width: 1920px) and (max-width: 2130px) {
    /* CSS代码 */
    html {
        font-size: 16px !important;
    }
 }
  • 4
    点赞
  • 15
    收藏
    觉得还不错? 一键收藏
  • 3
    评论
如果你的Qt应用程序在高缩放级别(如225%)下显示不完全,可能是因为你的应用程序没有正确处理高DPI缩放。你可以使用以下方法来解决这个问题: 1. 设置Qt应用程序的高DPI缩放因子:在应用程序的main()函数中,使用QApplication::setAttribute()方法来启用高DPI支持,并使用QApplication::setHighDpiScaleFactor()方法来设置高DPI缩放因子。例如,下面的代码将应用程序的高DPI缩放因子设置为2.25: ``` int main(int argc, char *argv[]) { QApplication::setAttribute(Qt::AA_EnableHighDpiScaling); QApplication app(argc, argv); app.setHighDpiScaleFactor(2.25); ... } ``` 2. 使用Qt的布局管理器:使用Qt的布局管理器可以确保你的应用程序在不同的窗口大小和分辨率下正确地缩放显示。如果你的应用程序没有使用布局管理器,请尝试将其添加到你的界面中。 3. 使用像素密度独立的字体:Qt的字体类支持像素密度独立的字体,这些字体可以在不同的分辨率和缩放下正确显示。你可以使用QFont类的setPixelSize()方法来设置像素密度独立的字体大小。 4. 使用矢量图形:矢量图形可以无损地缩放,因此它们是在高分辨率屏幕上正确显示的理想选择。Qt支持许多矢量图形格式,如SVG和PDF。 如果你的应用程序已经使用了上述方法,但仍然在高缩放级别下显示不完全,请确保你的应用程序没有使用绝对像素值来定位和调整界面元素的大小和位置。相反,你应该使用相对像素值(例如百分比)或像素密度独立的值来调整界面元素的大小和位置。

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 3
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值