html刘海屏高度,iphone刘海屏网页适配方法

1. 下面是实现iphonex 刘海屏前端网页适配的一个插值算法小案例

2020110616122418417.gif

Title

body, ul {

margin: 0;

}

ul {

padding-left: 10px;

}

li {

list-style: none;

}

.phone {

position: relative;

width: 600px;

height: 300px;

border: 10px solid #000;

border-radius: 30px;

margin: 100px auto 0;

}

.content, .content ul {

width: 100%;

height: 100%;

}

.content {

overflow-x: hidden;

overflow-y: scroll;

}

.camera {

position: absolute;

top: 60px;

left: 0;

width: 26px;

height: 180px;

background-color: black;

border-radius: 0 30px 30px 0;

}

li + li {

border-top: 1px solid #ccc;

}

li {

font-size: 16px;

padding: 5px;

}

*::-webkit-scrollbar {

padding-left: 100px;

}

  • SweeTango
  • Pacific Rose
  • SnapDragon
  • Envy
  • Koru (Plumac)
  • Pink Lady (Cripps Pink)
  • HoneYcrisp
  • Hoyal Gala
  • Macoun
  • SweeTango
  • Pacific Rose
  • SnapDragon
  • Envy
  • Koru (Plumac)
  • Pink Lady (Cripps Pink)
  • HoneYcrisp
  • Hoyal Gala
  • Macoun
  • Macoun
  • SweeTango
  • Pacific Rose
  • SnapDragon
  • Envy
  • Koru (Plumac)
  • Pink Lady (Cripps Pink)
  • HoneYcrisp
  • Hoyal Gala
  • Macoun

~~function () {

var thresh = 20;

var maxoffset = 50;

var aLi = document.querySelectorAll('li');

var oCamera = document.querySelector('.camera');

var oContent = document.querySelector('.content')

var camPs = oCamera.getBoundingClientRect();

~~function () {

oContent.onscroll = arguments.callee;

for (var item of aLi) {

var itemRect = item.getBoundingClientRect();

var dtf = itemRect.bottom - camPs.top

var dtb = itemRect.bottom - camPs.bottom

if (Math.abs(dtf) < 20) {

item.style.transform = 'translateX(' + lerp(0, 30, cal(dtf, 20)) + "px)";

} else if (dtf > 20 && dtb < -20) {

item.style.transform = 'translateX(' + 30 + "px)";

} else if (Math.abs(dtb) <20) {

item.style.transform = 'translateX(' + lerp(30, 0, cal(dtb, 20)) + "px)";

} else {

//全部移除摄像头区域

item.style.transform = 'translateX(' + 0 + "px)";

}

}

}()

}()

/**

* @param 插值算法

* @param p1 初始化状态

* @param p2 结束状态

* @param t 时间函数 (0-100%)

*

* 返回p1 到 p2 之间的值

*/

function lerp(p1, p2, t) {

return (p2 - p1) * t + p1

}

function cal(dis, thr) {

return (dis + thr) / (thr * 2)

}

以上所述是小编给大家简介的iphone刘海屏网页适配方法详解整合,希望对大家有所帮助,如果大家有任何疑问请给我留言,小编会及时回复大家的。在此也非常感谢大家对乐购源码网址的支持!

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值