Created
December 10, 2019 09:26
-
-
Save CyberAP/01df369fd7ea11977dda390f9be7e873 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| import Vue from 'vue'; | |
| import getScrollbarWidth from "@modules/utils/getScrollbarWidth.js"; | |
| import { getDocument, getWindow } from "@modules/utils/dom.js"; | |
| const window = getWindow(); | |
| const document = getDocument(); | |
| const mobileWidth = parseInt( | |
| window | |
| .getComputedStyle(document.documentElement) | |
| .getPropertyValue('--screen-mobile') | |
| ) - 1; | |
| function getCurrentWidth() { | |
| return document.body.clientWidth; | |
| } | |
| function getScreenHeight() { | |
| return window.innerHeight; | |
| } | |
| export const responsive = Vue.observable({ | |
| width: getCurrentWidth(), | |
| screenHeight: getScreenHeight(), | |
| get isMobile() { | |
| return this.width + getScrollbarWidth() <= mobileWidth; | |
| }, | |
| mobileWidth, | |
| }); | |
| window.addEventListener('resize', (event) => { | |
| responsive.width = getCurrentWidth(); | |
| responsive.screenHeight = getScreenHeight(); | |
| }); | |
| const install = Vue => { | |
| Vue.mixin({ | |
| provide: { | |
| responsive, | |
| } | |
| }); | |
| }; | |
| export default { install }; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment