站长资源网页制作

IphoneX底部适配的实现

整理:jimmy2024/12/24浏览2
简介1.判断是否是IPhoneX手机let isIphone = /iphone/gi.test(window.navigator.userAgent)let windowW = window.screen.widthlet windowH = window.screen.heightlet pixel

1.判断是否是IPhoneX手机

let isIphone = /iphone/gi.test(window.navigator.userAgent)
  let windowW = window.screen.width
  let windowH = window.screen.height
  let pixelRatio = window.devicePixelRatio

  let isIPhoneX = isIphone && pixelRatio && pixelRatio === 3 && windowW === 375 && windowH === 812
  let isIPhoneXSMax = isIphone && pixelRatio && pixelRatio === 3 && windowW === 414 && windowH === 896
  let isIPhoneXR = isIphone && pixelRatio && pixelRatio === 2 && windowW === 414 && windowH === 896

  if (isIPhoneX || isIPhoneXSMax || isIPhoneXR) {
    // 底部增加fix-iphonex-bottm 样式
    $(".contact-box").addClass('fix-iphonex-bottom')
    // 底部增加iphone-footer-bg样式 初始none,条件满足block
    $(".iphone-footer-bg").addClass('iphonexshow')
  }

2.增加fix-iphonex-bottom样式

.fix-iphonex-bottom {
  bottom: 34px !important;
}

如果想更改IPhoneX底部34像素的背景颜色怎么办呢?

3.增加iphone-footer-bg样式

.iphone-footer-bg {
  height: 34px;
  background: #6D6D6D;
  width: 100%;
  position: absolute;
  bottom: -33px;
  display: none;
}
.iphonexshow {
  display: block !important;
}

以上就是本文的全部内容,希望对大家的学习有所帮助,也希望大家多多支持。