Redbattle
踩坑
环境
项目
配置
知识点
踩坑
环境
项目
配置
知识点
  • 视频方案
  • DNS
  • 主题切换
  • 图片性能优化
  • 富文本预览
  • 区域滚动方法
  • 底部固定区域
  • CSS实现背景透明文字不透明
  • 文字展开收起
  • 二次开发
  • scheme
2024-06-07

底部固定区域

<template>
  <div class="bottom-fixed" :style="boxStyle">
    <div class="bottom-fixed-container" ref="fixed_container">
      <slot />
    </div>
  </div>
</template>

<script>
  export default {
    name: 'BottomFixed',
    data() {
      return {
        boxStyle: {}
      }
    },
    mounted() {
      this.setStyle()
    },
    methods: {
      setStyle() {
        const containerH = this.$refs['fixed_container']?.offsetHeight || 0
        if (containerH) {
          this.boxStyle = {
            '--container_height': `${containerH}px`
          }
        } else {
          this.boxStyle = {}
        }
      }
    }
  }
</script>

<style lang="less" scoped>
  .bottom-fixed {
    --container_height: 0;
    padding-bottom: var(--container_height);
    &-container {
      position: fixed;
      bottom: 0;
      width: 100%;
      z-index: 10;
    }
  }
  // 需要在 meta 标签设置 viewport=cover
  @supports (bottom: constant(safe-area-inset-top)) or (bottom: env(safe-area-inset-top)) {
    @safe_bottom: constant(safe-area-inset-bottom); // < ios 11.2
    @safe_bottom: env(safe-area-inset-bottom); // > ios 11.2
    .bottom-fixed {
      padding-bottom: calc(var(--container_height) + @safe_bottom);
      &-container {
        padding-bottom: @safe_bottom;
      }
    }
  }
</style>
最近更新
01
烧虾球
05-13
02
二次开发
12-20
03
文字展开收起
10-17
更多文章>
Theme by Vdoing
  • 跟随系统
  • 浅色模式
  • 深色模式
  • 阅读模式