js部分:
样式部分:
@r:100; //固定头部和尾部,中间部分可滑动,使用flex布局 //html, body{ background:url("//storage.jd.com/1901/04nianhuojie/02lingquanbg_02.png") repeat-y; background-size:100%; height:100%; } .main-warp{ max-width:750px; min-height:100%; margin:0auto; display:flex; flex-direction:column; height:100%; width:100%; box-sizing:border-box; .header{ height:500rem/@r; .header-img{ height:500rem/@r; } } .content{ flex:1; width:100%; overflow:hidden; //overflow:auto; //-webkit-overflow-scrolling:touch; .shop-box{ margin:50rem/@r0; img{ width:106rem/@r; } } } .footer{ background:url("//storage.jd.com/1901/04nianhuojie/fixbtnbg_02.png")repeat; background-size:12rem/@r11rem/@r; height:82rem/@r; width:100%; bottom:0; color:#ffdeb8; font-size:34rem/@r; line-height:82rem/@r; text-align:center; font-weight:bolder; max-width:750px; } }
说明一下,在移动端,如果直接使用
overflow: auto;
-webkit-overflow-scrolling: touch;
的话 ,在ios上,如果手指滑动超出了盒子的区域,那么很容易再次滑动的时候,导致区域不能滑动的问题,那样子就好像是手指没有点到那个盒子一样,所以这里使用了BScroll插件,使用IScroll也是一样的。
他的最终效果就是把content的直接子元素加了transition效果。
在此记录该布局方式
注:注意 这种布局方式在ios9.3及其以下版本不兼容,flex布局在需要兼容低版本ios时还是需要慎用的哦
看完了这篇文章,相信你对“flex布局如何实现上下固定中间滑动”有了一定的了解,如果想了解更多相关知识,欢迎关注恰卡编程网行业资讯频道,感谢各位的阅读!
发布于 2021-03-21 22:37:23