2

I have page with min-height: 100vh and it renders on mobile browsers with some overflow on bottom. And I use this script to fix it:

  methods: {
    calcVH() {
      const vH = Math.max(document.documentElement.clientHeight, window.innerHeight, window.screen.height || 0)
      document.getElementById('app').style.height = vH + 'px';
    }
  },
  mounted() {
    this.calcVH();
    window.addEventListener('onorientationchange', this.calcVH, true);
    window.addEventListener('resize', this.calcVH, true);
  }

It works ok in emulator, but it doesn't work on chrome/safari mobile. Did anyone have same problem?

kipris
  • 2,899
  • 3
  • 20
  • 28

2 Answers2

4

Yes, I had similar issues using vh. It's a known problem.

My suggestion for you is to stop using vh on mobile and tablets in order to avoid these kind of hacks around. Use classic relative % (percentage) values instead. Since I've replaced vh with % I have no such problems on mobiles but it requires a bit more implementation effort. Using % isn't straightforward in all cases, but it pays you back since you've got a solution which works pretty everywhere in the same predictable way.

klimat
  • 24,711
  • 7
  • 63
  • 70
0

This VueJS component is designed to solve it:

<template>
  <vue100vh :css="{height: '100rvh';}">
    <marquee>Your stuff goes here</marquee>
  </vue100vh>
</template>

<script>
import vue100vh from 'vue-100vh'

export default {
  components: { vue100vh },
}
</script>

Works for smaller percentages ... where rvh = "real viewport height".

<vue100vh :style="{ minHeight: '50rvh' }">
  <marquee>This is inside a div that takes at least 50% of viewport height.</marquee>
</vue100vh>
Tony O'Hagan
  • 21,638
  • 3
  • 67
  • 78