Skip to content

Instantly share code, notes, and snippets.

@spac3unit
Forked from CyberAP/responsive.js
Created March 10, 2021 09:02
Show Gist options
  • Select an option

  • Save spac3unit/4359656c446f1084c9e69571fc76acbd to your computer and use it in GitHub Desktop.

Select an option

Save spac3unit/4359656c446f1084c9e69571fc76acbd 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