flex布局实现上下固定中间滑动的布局方式
本文主要介绍了flex布局实现上下固定中间滑动的布局方式,分享给大家,具体如下:
例如这样的一个页面,希望有个头图,有个底部的底栏,中部内容区域可滑动。
简单介绍一下如何实现
固定头部和尾部,中间部分可滑动,使用flex布局
1.设置html,body高度为100%
2.设置最外层div的布局方式为弹性布局display:flex;
3.设置最外层div的主轴方向为flex-direction: column;主轴为垂直方向,起点在上沿
row(默认值)主轴为水平方向,起点在左端。
row-reverse主轴为水平方向,起点在右端。
column主轴为垂直方向,起点在上沿。
column-reverse主轴为垂直方向,起点在下沿。
4.设置最外层div的高度为100%
5.正常写头部样式
6.正常写尾部样式
7.中间样式为flex: 1;overflow: hidden或者overflow:auto;-webkit-overflow-scrollg: touch后者在ios手机中滑动会有问题,建议使用插件
html部分
<div class="ma-warp"> <div class="header"> <img src="imgurl" class="header-img" alt> </div> <div class="content"> <div class="content-scroll"> <div class="shop-box"> <img src="imgurl" alt> </div> <div class="shop-box"> <img src="imgurl" alt > </div> <div class="shop-box"> <img src="imgurl" alt > </div> <div class="shop-box"> <img src="imgurl" alt > </div> </div> </div> <div class="footer"></div> </div>
js部分:
<script> import BScroll from 'better-scroll' export default { data () { return { } }, ponents: { }, methods: { }, puted: { }, mounted () { this.$nextTick(function () { / eslt-disable no-new / let pageBottom = document.querySelector('.content') new BScroll(pageBottom, { click: true }) }) }, created () { } } </script>
样式部分
<style lang="less" rel="stylesheet/less" type="text/less"> @r: 100; // 固定头部和尾部,中间部分可滑动,使用flex布局 // html, body { background: url("//storage.jd./1901/04nianhuojie/02lgquanbg_02.png") repeat-y; background-size: 100%; height: 100%; } .ma-warp { max-width: 750px; m-height: 100%; marg: 0 auto; display: flex; flex-direction: column; height: 100%; width: 100%; box-sizg: border-box; .header { height: 500rem / @r; .header-img { height: 500rem / @r; } } .content { flex: 1; width: 100%; overflow: hidden; // overflow: auto; // -webkit-overflow-scrollg: touch; .shop-box { marg: 50rem / @r 0; img { width: 106rem / @r; } } } .footer { background: url("//storage.jd./1901/04nianhuojie/fixbtnbg_02.png") repeat; background-size: 12rem / @r 11rem / @r; height: 82rem / @r; width: 100%; bottom: 0; color: #ffdeb8; font-size: 34rem / @r; le-height: 82rem / @r; text-align: center; font-weight: bolder; max-width: 750px; } } </style>
说明一下,在移动端,如果直接使用
overflow: auto;
-webkit-overflow-scrollg: touch;
的话 ,在ios上,如果手指滑动超出了盒子的区域,那么很容易滑动的时候,导致区域不能滑动的问题,那样子就好像是手指没有点到那个盒子一样,所以这里使用了BScroll插件,使用IScroll也是一样的。
他的最终效果就是把content的直接子元素加了transition效果。
在此记录该布局方式
注注意 这种布局方式在ios9.3及其以下版本不兼容,flex布局在需要兼容低版本ios时还是需要慎用的哦
到此这篇关于flex布局实现上下固定中间滑动的布局方式的文章就介绍到这了,更多相关flex上下固定中间滑动布局内容请搜索狼蚁SEO以前的文章或继续浏览狼蚁网站SEO优化的相关文章,希望大家以后多多支持狼蚁SEO!
网站设计
- 静宁会SEO的网站建设公司:全面提升您的网络影
- 提升在线业务的关键:选择最佳的丽水网站建设
- 浙江网站优化发展潜力如何
- 井研专业的网站建设公司:打造您的在线品牌
- 灵山SEO网站建设公司:提升您的在线业务表现
- 蒙城网站建设优化公司:提升您网站表现的理想
- 阳谷企业网站优化:提升线上业务力的关键
- 樟树专业的网站建设公司:打造您在线业务的坚
- 通河百度SEO排名的策略与技巧
- 重庆百度快照排名如何进行精准的客户引流
- 重庆百度快照排名
- 常宁便宜的建站公司:助您轻松打造在线业务
- 巫溪百度网站优化:提升网站曝光率与流量的关
- 湖北整站优化怎么做才能放大客户需求
- 闸北网站建设多少钱?全面解析与预算规划
- 辽宁企业网站优化怎么做电话营销