前端PC适配,火狐,IE浏览器

 之前发的PC端的适配我发现在火狐和IE等一些浏览器老版本内核的情况下没办法实现,原因是zoom属性内核过老无法识别到这个属性,那个我又想到了这个方案,原理是一样的,只是采用不一样的css属性进行封装

    // 设计稿:1920 * 1080
    // 设配目标:1920 * 1080 ( 1 : 1) | 3840* 2160 ( 2 : 2 ) | 7680 * 2160 ( 4 : 2)
 
    // 1.设计稿尺寸
    let targetWidth = 1920;
    let targetHeight = 1080;
 
    let targetRatio = 16 / 9; // 宽高比率 (宽 / 高)
 
    // 2.拿到当前设备(浏览器)的宽度
    let currentWidth =
      document.documentElement.clientWidth || document.body.clientWidth;
    let currentHeight =
      document.documentElement.clientHeight || document.body.clientHeight;
    // 3.计算缩放比率(屏幕过宽,根据高度计算缩放比例)
    let scaleRatio = currentWidth / targetWidth; // 参照宽度进行缩放(默认情况下)
 
    // 当前宽高比例
    let currentRatio = currentWidth / currentHeight;
 
    if (currentRatio > targetRatio) {
      scaleRatio = currentHeight / targetHeight; // 参照高度进行缩放(屏幕很宽的情况下)
      document.body.style = `transform: scale(${scaleRatio}) translateX(-50%); left: 50%;`;
    } else {
      // 4.开始缩放网页
      document.body.style = `transform: scale(${scaleRatio})`;

  • 13
    点赞
  • 12
    收藏
    觉得还不错? 一键收藏
  • 1
    评论

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值