All Projects → mvasin → React Div 100vh

mvasin / React Div 100vh

Licence: mit
A workaround for the '100vh' issue in mobile browsers

Programming Languages

typescript
32286 projects

Projects that are alternatives of or similar to React Div 100vh

vue-slim-cropper
💇‍♀️ A simple and elegant mobile image crop upload component for Vue 2.x | 简洁易用的 vue 移动端图片裁剪上传组件
Stars: ✭ 34 (-95.19%)
Mutual labels:  mobile-web
Qmlcore
QML to Javascript/HTML5 translator, both for mobile and desktop targets
Stars: ✭ 258 (-63.51%)
Mutual labels:  mobile-web
Islider
如丝般高性能H5全屏滑动组件
Stars: ✭ 444 (-37.2%)
Mutual labels:  mobile-web
servonk
Servo on Gonk
Stars: ✭ 84 (-88.12%)
Mutual labels:  mobile-web
quiz-app
🏆 QuizApp is a free and open-source quiz application that lets you play fully customized quizzes right in the browser.
Stars: ✭ 97 (-86.28%)
Mutual labels:  mobile-web
Yo
Lightweight, easy-to-use, configurable, and extensible mobile front-end development framework.
Stars: ✭ 319 (-54.88%)
Mutual labels:  mobile-web
scrollbounce
Add a subtle bounce effect on mobile when the user scrolls (WIP)
Stars: ✭ 17 (-97.6%)
Mutual labels:  mobile-web
Vant Mobile Mall
基于有赞 vant 组件库的移动商城
Stars: ✭ 638 (-9.76%)
Mutual labels:  mobile-web
Pwa Fundamentals
👨‍🏫 Mike & Steve's Progressive Web Fundamentals Course
Stars: ✭ 256 (-63.79%)
Mutual labels:  mobile-web
Phonon
Phonon is a responsive front-end framework with a focus on simplicity and flexibility
Stars: ✭ 425 (-39.89%)
Mutual labels:  mobile-web
fao
Party game based on Oink Games' tabletop game, "A Fake Artist Goes to New York." Draw with your phone or a mouse.
Stars: ✭ 70 (-90.1%)
Mutual labels:  mobile-web
ember-add-to-homescreen
📲 "Add to Home Screen" prompt for mobile web Ember.js experiences
Stars: ✭ 23 (-96.75%)
Mutual labels:  mobile-web
Vux
Mobile UI Components based on Vue & WeUI
Stars: ✭ 17,573 (+2385.57%)
Mutual labels:  mobile-web
scruffy-server
Scruffy micro web server to have your own UML class/sequence diagram page like yUML and even more lean.
Stars: ✭ 44 (-93.78%)
Mutual labels:  mobile-web
Vkui
VKUI – это набор React-компонентов, с помощью которых можно создавать интерфейсы, внешне неотличимые от наших iOS и Android приложений.
Stars: ✭ 485 (-31.4%)
Mutual labels:  mobile-web
vue-vant-template
A reliable mobile-web template built on Vue, Vue-CLI, Vuex, Vue-Router, Vant, Axios, Scss, Mock, Eslint and Viewport adaptation scheme. 基于 Vue 全家桶和 Vant 的 Web 移动端开发脚手架。
Stars: ✭ 15 (-97.88%)
Mutual labels:  mobile-web
Docker Android
Android in docker solution with noVNC supported and video recording
Stars: ✭ 4,042 (+471.71%)
Mutual labels:  mobile-web
Weui
A UI library by WeChat official design team, includes the most useful widgets/modules in mobile web applications.
Stars: ✭ 26,030 (+3581.75%)
Mutual labels:  mobile-web
Oho Reader
【停止维护】哦豁阅读器!API源自追书神器,免费使用!填坑完成!使用react
Stars: ✭ 571 (-19.24%)
Mutual labels:  mobile-web
Pdfh5
web/h5/移动端PDF预览插件
Stars: ✭ 423 (-40.17%)
Mutual labels:  mobile-web

Div100vh React component and use100vh React hook

npm version

This is a workaround for iOS Safari and other mobile browsers.

The problem

In mobile browsers, the real height of the viewport is dynamic, as browser "chrome" (panels) slide away on scrolling. The browser developers faced two choices: either to reflow the page as the pixel value of a vh changes, or ignore the fact that the browser panel covers part of the screen.

The browser panels are supposed to slide away smoothly, and because the layout reflow during scrolling will not look smooth, the browser developers went for the second option.

It may work for the most of use cases, but if you're looking for an app-like full-screen experience, or want to make sure that the call to action button at the bottom of your splash screen isn't covered, you may need to know the fair value of a vh.

<div style={{height: '100vh'}}> <Div100vh>
Page cropped by bottom Safari chrome Page cropped by bottom Safari chrome

More on this issue here.

The solution

Div100vh React component is the default export:

import Div100vh from 'react-div-100vh'

const MyFullHeightComponent = () => (
  <Div100vh>
    <marquee>Look ma, no crop!</marquee>
  </Div100vh>
)

For more advanced use cases (for instance, if you need 50% of the real height), there is a named export use100vh. This React hook provides an accurate vertical height in pixels. The return type is a number in a browser and null in Node environment. You may need to check if it's not null if you're doing SSR, otherwise, manipulate the value as you wish and concatenate the result with px:

import { use100vh } from 'react-div-100vh'

const MyHalfHeightExampleComponent = ({ children }) => {
  const height = use100vh()
  const halfHeight = height ? height / 2 : '50vh'
  return <div style={{ height: halfHeight }}>{children}</div>
}

Under the hood use100vh uses measureHeight function which is exported as well, so feel free to use it, even without React. Currently it returns document.documentElement?.clientHeight || window.innerHeight or null.

Testing

This component is tested with BrowserStack Logo.

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].