-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathMotionBlurCursor.vue
107 lines (94 loc) · 2.02 KB
/
MotionBlurCursor.vue
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
<script setup lang="ts">
import { gsap } from 'gsap'
import { isDark } from '@/logic'
</script>
<script lang="ts">
export default defineComponent({
name: 'MotionBlurCursor',
data() {
return {
// cursor elements
cursorRefs: [] as Element[],
// cursor pos relative to screen
cursorX: 0,
cursorY: 0,
// scrolled amount relative to document
scrollX: 0,
scrollY: 0,
}
},
mounted() {
if (window.innerWidth >= 992) {
document.documentElement.setAttribute('data-custom-cursor', '')
// initialize circle cursor
this.initMotionBlurCursor()
}
},
methods: {
// initialize circle cursor
initMotionBlurCursor() {
const app = this.$root?.$el
const collection = document.getElementsByClassName('blur-cursor')
this.cursorRefs = [...collection]
app.addEventListener('mousemove', (e: MouseEvent) => {
this.cursorX = e.clientX
this.cursorY = e.clientY
this.moveCursor()
})
},
moveCursor() {
this.cursorRefs.forEach((val, index) => {
const posX = this.scrollX + this.cursorX
const posY = this.scrollY + this.cursorY
gsap.to(val, {
duration: 0.05,
css: { left: posX, top: posY },
delay: 0 + index / 750,
})
})
},
},
})
</script>
<template>
<div class="cursor-canvas">
<div
v-for="i in 30"
:key="i"
class="blur-cursor"
:style="isDark ? 'background: #fff1;' : 'background: #0001;'"
/>
</div>
</template>
<style lang="scss">
html[data-custom-cursor] {
.blur-cursor {
opacity: 1;
}
* {
cursor: none;
}
}
.blur-cursor {
z-index: 999999;
position: absolute;
width: 25px;
height: 25px;
top: 50%;
left: 50%;
margin: -12.5px 0 0 -12.5px;
border-radius: 50px;
opacity: 0;
user-select: none;
pointer-events: none;
}
.cursor-canvas {
position: fixed;
inset: 0;
z-index: 999998;
width: 100vw;
height: 100vh;
user-select: none;
pointer-events: none;
}
</style>