summaryrefslogtreecommitdiffstats
path: root/src/mixins/mobile.js
diff options
context:
space:
mode:
Diffstat (limited to 'src/mixins/mobile.js')
-rw-r--r--src/mixins/mobile.js44
1 files changed, 44 insertions, 0 deletions
diff --git a/src/mixins/mobile.js b/src/mixins/mobile.js
new file mode 100644
index 0000000..c44edcf
--- /dev/null
+++ b/src/mixins/mobile.js
@@ -0,0 +1,44 @@
+export default {
+
+ data() {
+ return {
+ windowWidth: window.innerWidth,
+ };
+ },
+
+ created() {
+ window.addEventListener("resize", this.onResize);
+ this.updateBody();
+ },
+
+ methods: {
+ /**
+ * Handle screen resize
+ * @returns {void}
+ */
+ onResize() {
+ this.windowWidth = window.innerWidth;
+ this.updateBody();
+ },
+
+ /**
+ * Add css-class "mobile" to body if needed
+ * @returns {void}
+ */
+ updateBody() {
+ if (this.isMobile) {
+ document.body.classList.add("mobile");
+ } else {
+ document.body.classList.remove("mobile");
+ }
+ }
+
+ },
+
+ computed: {
+ isMobile() {
+ return this.windowWidth <= 767.98;
+ },
+ },
+
+};