Skip to content

Instantly share code, notes, and snippets.

@CyberAP
Created December 10, 2019 09:26
Show Gist options
  • Select an option

  • Save CyberAP/01df369fd7ea11977dda390f9be7e873 to your computer and use it in GitHub Desktop.

Select an option

Save CyberAP/01df369fd7ea11977dda390f9be7e873 to your computer and use it in GitHub Desktop.
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