Skip to content
This repository was archived by the owner on Feb 24, 2023. It is now read-only.

Commit d28c3ab

Browse files
author
Łukasz Florczak
committed
Handlers methods mixin
1 parent f89762f commit d28c3ab

File tree

1 file changed

+49
-0
lines changed

1 file changed

+49
-0
lines changed

src/mixins/handlers.js

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
/**
2+
* Handlers methods for mouse/touch events
3+
*/
4+
const mixin = {
5+
methods: {
6+
handleMouseDown (e) {
7+
if (!e.touches) {
8+
e.preventDefault()
9+
}
10+
this.mouseDown = true
11+
this.dragStartX = ('ontouchstart' in window) ? e.touches[0].clientX : e.clientX
12+
this.dragStartY = ('ontouchstart' in window) ? e.touches[0].clientY : e.clientY
13+
},
14+
15+
handleMouseMove (e) {
16+
let positionX = ('ontouchstart' in window) ? e.touches[0].clientX : e.clientX
17+
let positionY = ('ontouchstart' in window) ? e.touches[0].clientY : e.clientY
18+
let dragDistanceX = Math.abs(positionX - this.dragStartX)
19+
let dragDistanceY = Math.abs(positionY - this.dragStartY)
20+
if (dragDistanceX > 3 * dragDistanceY) {
21+
this.disableScroll()
22+
this.dragDistance = positionX - this.dragStartX
23+
}
24+
},
25+
26+
handleMouseUp () {
27+
this.mouseDown = false
28+
this.enableScroll()
29+
},
30+
31+
handleMouseOver (element) {
32+
if (this.settings.autoplay) {
33+
if ((element === 'dot' && this.settings.pauseOnDotsHover) || (element === 'track' && this.settings.pauseOnHover)) {
34+
this.pauseAutoPlay = true
35+
}
36+
}
37+
},
38+
39+
handleMouseOut (element) {
40+
if (this.settings.autoplay) {
41+
if ((element === 'dot' && this.settings.pauseOnDotsHover) || (element === 'track' && this.settings.pauseOnHover)) {
42+
this.pauseAutoPlay = false
43+
}
44+
}
45+
}
46+
}
47+
}
48+
49+
export default mixin

0 commit comments

Comments
 (0)