Skip to content

Commit

Permalink
simplify with one hook, update readme
Browse files Browse the repository at this point in the history
  • Loading branch information
sdras committed Jan 21, 2019
1 parent 0c457d5 commit 60b319b
Show file tree
Hide file tree
Showing 4 changed files with 27 additions and 40 deletions.
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,5 +8,5 @@ If you'd like to see them in action, check out `src/hooks` and `src/AppGrid.vue`

Created by [Vue CLI](https://cli.vuejs.org/)

To run: `yarn run serve`
To build: `yarn run build`
* To run: `yarn run serve`
* To build: `yarn run build`
3 changes: 0 additions & 3 deletions src/components/AppDetails.vue
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,6 @@

<script>
import { preventscroll } from "./../hooks/preventscroll.js";
import { enablescroll } from "./../hooks/enablescroll.js";
import { TimelineMax, TweenMax, Sine, Elastic } from "gsap";
import Splitting from "splitting";
import "splitting/dist/splitting.css";
Expand All @@ -38,7 +36,6 @@ export default {
},
hooks() {
preventscroll();
enablescroll();
},
methods: {
lettering() {
Expand Down
27 changes: 0 additions & 27 deletions src/hooks/enablescroll.js

This file was deleted.

33 changes: 25 additions & 8 deletions src/hooks/preventscroll.js
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
import { useMounted } from "vue-hooks";
import { useDestroyed, useMounted } from "vue-hooks";

export function preventscroll() {
useMounted(() => {
const preventDefault = (e) => {
e = e || window.event;
if (e.preventDefault)
e.preventDefault();
e.returnValue = false;
}
const preventDefault = (e) => {
e = e || window.event;
if (e.preventDefault)
e.preventDefault();
e.returnValue = false;
}

useMounted(() => {
// keycodes for left, up, right, down
const keys = { 37: 1, 38: 1, 39: 1, 40: 1 };

Expand All @@ -28,4 +28,21 @@ export function preventscroll() {
document.onkeydown = preventDefaultForScrollKeys;
})()
});

useDestroyed(() => {
(() => {
if (window.removeEventListener)
window.removeEventListener('DOMMouseScroll', preventDefault, false);

//firefox
window.addEventListener('DOMMouseScroll', (e) => {
e.stopPropagation();
}, true);

window.onmousewheel = document.onmousewheel = null;
window.onwheel = null;
window.ontouchmove = null;
document.onkeydown = null;
})()
});
}

0 comments on commit 60b319b

Please sign in to comment.