h5移动端上下布局

本文详细探讨了在H5移动端实现上下布局的各种方法,包括Flexbox布局、Grid布局以及传统的CSS定位技术。通过实例代码展示如何适配不同屏幕尺寸,确保内容区域和头部/底部栏稳定显示。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

<template>
  <div class="home" id="home">
    <div class="header">头部</div>
    <div class="content">
      <div class="nav">导航</div>
      <div class="banner">banner</div>
      <div class="list-box">
        <div class="list-tab" :class="{'move':scrollTopMove}">list-tab</div>
        <ul>
          <li v-for="item in 100">
            {{item}}
          </li>
        </ul>
      </div>
    </div>
    <div class="bottom-nav">底部</div>
  </div>
</template>

<script>


  export default {
    name   : 'Gift',
    data() {
      return {
        scrollTop:0
      }
    },
    mounted() {
      var last_known_scroll_position = 0;
      var ticking = false;
      let _this = this;

      function doSomething(scroll_pos) {
        console.log('scroll_pos',scroll_pos)
        _this.scrollTop = scroll_pos
      }

      window.addEventListener('scroll', (e)=> {
        last_known_scroll_position = window.scrollY|(window.pageYOffset || document.documentElement.scrollTop || document.body.scrollTop);
        if (!ticking) {
          window.requestAnimationFrame(()=> {
            doSomething(last_known_scroll_position);
            ticking = false;
          });
        }
        ticking = true;
      });

    },
    computed: {
      scrollTopMove(){
        return this.scrollTop > 200
      }
    },
    methods: {
      scroll(e) {
        this.scrollTop = e.target.scrollTop
      }
    }
  }
</script>

<style lang="less">
  .home {
    /*position: absolute;
    top: 0;
    left: 0;*/
    width: 100%;
    height: 100%;
    //overflow: auto;
    padding-top: 50px;
    padding-bottom: 50px;
    .header {
      height: 50px;
      background: beige;
      font-size: 30px;
      width: 100%;
      position: fixed;
      top: 0;
      left: 0;
      z-index: 1000;
    }

    .nav {
      height: 80px;
      background: green;
    }

    .content {
      width: 100%;
      height: 100%;
      background: #ccc;
    }

    .banner {
      height: 200px;
      background: #ea5e56;
    }

    .list-tab {
      width: 100%;
      height: 50px;
      text-align: center;
      background: fuchsia;
    }

    .move {
      position: fixed;
      top: 50px;
    }

    .bottom-nav {
      width: 100%;
      height: 50px;
      background: beige;
      font-size: 30px;
      position: fixed;
      bottom: 0;
      left: 0;
      z-index: 1000;
    }
  }

</style>

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值