Skip to content

Commit

Permalink
feat(UI): Introducing new component to apply a custom cursor to a spe…
Browse files Browse the repository at this point in the history
…cific area of the DOM (#125)
  • Loading branch information
IvanM3x authored Sep 6, 2021
1 parent 59bcdd2 commit 779f588
Show file tree
Hide file tree
Showing 3 changed files with 68 additions and 0 deletions.
4 changes: 4 additions & 0 deletions components/ui/CustomCursorArea/CustomCursorArea.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
<div id="custom-cursor-area" @mouseover="hideCursor = false" @mouseleave="hideCursor = true">
<div v-if="!hideCursor" id="custom-cursor" ref="point" :style="cursorPoint"></div>
<slot />
</div>
33 changes: 33 additions & 0 deletions components/ui/CustomCursorArea/CustomCursorArea.less
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
#custom-cursor {
top: 0;
left: 0;
position: fixed;
width: 30px;
height: 30px;
pointer-events: none;
user-select: none;
border-radius: 100%;
z-index: 55555555;
backface-visibility: hidden;
will-change: transform;
box-shadow: 0 0 8px #fff, inset 0 0 8px #fff;
-webkit-animation: pulse 2s linear 1s infinite;
background: -webkit-radial-gradient(
rgba(255, 255, 255, 0.2),
rgba(255, 255, 255, 0.4),
rgba(255, 255, 255, 0.7)
);
opacity: 0.4;
}

@-webkit-keyframes pulse {
0% {
box-shadow: 0 0 8px #fff, inset 0 0 8px #fff;
}
50% {
box-shadow: 0 0 20px #fff, inset 0 0 18px #fff;
}
100% {
box-shadow: 0 0 8px #fff, inset 0 0 8px #fff;
}
}
31 changes: 31 additions & 0 deletions components/ui/CustomCursorArea/CustomCursorArea.vue
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
<template src="./CustomCursorArea.html"></template>
<script lang="ts">
import Vue from 'vue'
export default Vue.extend({
data() {
return { xChild: 0, yChild: 0, xParent: 0, yParent: 0, hideCursor: true }
},
computed: {
cursorPoint(): string {
return `transform: translateX(${this.xChild - 15}px) translateY(${
this.yChild - 15
}px) translateZ(0) translate3d(0, 0, 0);`
},
},
methods: {
moveCursor(e: Event | any) {
this.xChild = e.clientX
this.yChild = e.clientY
setTimeout(() => {
this.xParent = e.clientX - 15
this.yParent = e.clientY - 15
}, 1000)
},
},
mounted() {
document.addEventListener('mousemove', this.moveCursor)
},
})
</script>
<style scoped lang="less" src="./CustomCursorArea.less"></style>

0 comments on commit 779f588

Please sign in to comment.