黑松山资源网 Design By www.paidiu.com
本文主要介绍了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-scrolling: touch后者在ios手机中滑动会有问题,建议使用插件
html部分:
<div class="main-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 { } }, components: { }, methods: { }, computed: { }, mounted () { this.$nextTick(function () { /* eslint-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.com/1901/04nianhuojie/02lingquanbg_02.png") repeat-y; background-size: 100%; height: 100%; } .main-warp { max-width: 750px; min-height: 100%; margin: 0 auto; 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 / @r 0; img { width: 106rem / @r; } } } .footer { background: url("//storage.jd.com/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; line-height: 82rem / @r; text-align: center; font-weight: bolder; max-width: 750px; } } </style>
说明一下,在移动端,如果直接使用
overflow: auto;
-webkit-overflow-scrolling: touch;
的话 ,在ios上,如果手指滑动超出了盒子的区域,那么很容易再次滑动的时候,导致区域不能滑动的问题,那样子就好像是手指没有点到那个盒子一样,所以这里使用了BScroll插件,使用IScroll也是一样的。
他的最终效果就是把content的直接子元素加了transition效果。
在此记录该布局方式
注:注意 这种布局方式在ios9.3及其以下版本不兼容,flex布局在需要兼容低版本ios时还是需要慎用的哦
黑松山资源网 Design By www.paidiu.com
广告合作:本站广告合作请联系QQ:858582 申请时备注:广告合作(否则不回)
免责声明:本站资源来自互联网收集,仅供用于学习和交流,请遵循相关法律法规,本站一切资源不代表本站立场,如有侵权、后门、不妥请联系本站删除!
免责声明:本站资源来自互联网收集,仅供用于学习和交流,请遵循相关法律法规,本站一切资源不代表本站立场,如有侵权、后门、不妥请联系本站删除!
黑松山资源网 Design By www.paidiu.com
暂无评论...
更新日志
2024年09月20日
2024年09月20日
- 【小提琴】陈立新《思乡曲》2004[FLAC+CUE]
- 《战地》新作明年初大规模测试!EA已内部测试一年
- 《GTAOL》PC版时隔多年更新反作弊!小助手宣布跑路
- EA称AI是其业务核心!能提高开发效率、节约成本
- 卫华.1990-太阳升【BMG】【WAV+CUE】
- 呼吸乐队.1992-THEBREATHING【深飞】【WAV+CUE】
- 李玟.2008-1994-2008豪华典藏精选2CD【SONY】【WAV+CUE】
- 《张学友 再现歌神的光辉岁月 梦想成真 2CD》[WAV/分轨][1.2GB]
- 《海来阿木 高音测试王》[WAV+CUE][500MB]
- 《许巍 歌声给你生命的力量 珍藏许巍 3CD》[WAV/分轨][2GB]
- 《直到黎明重制版》配置要求推荐
- 《赛博朋克2077》2.13版本更新内容一览
- 《神话时代:重述版》评测:粉丝们的朝花夕拾
- 战锤40K星际战士2先锋职业介绍|先锋职业技能效果一览
- 战锤40K星际战士2重装职业介绍|重装职业技能效果一览