a customizable animated cursor for VueJS Demo Github Page
npm install vue-magic-cursor
You can use MagicCursor either as a plugin (globally) or as a component (locally).
import MagicCursor from 'vue-magic-cursor'
import 'vue-magic-cursor/style.css' // optional feel free to add your own styling
const app = createApp(App)
app.use(MagicCursor)
app.mount('#app')
import { MagicCursor } from 'vue-magic-cursor'
import 'vue-magic-cursor/style.css' // optional feel free to add your own styling
export default {
components: {
MagicCursor
}
}
<template>
<div>
<MagicCursor />
</div>
</template>
The MagicCursor
component provides a scoped slot with the following props:
- isStopped: A boolean indicating whether the cursor is stopped.
- isHover: A boolean indicating whether the cursor is hovering over an element.
You may use those values for hover effects, idle effects, etc.
<MagicCursor>
<template v-slot:default="{ isStopped, isHover }">
<div>
<!-- custom cursor here -->
</div>
</template>
<template #follower
v-slot:follower="{ isStopped, isHover }"
>
<!-- Custom cursor follower here -->
</template>
</MagicCursor>
The MagicCursor
component accepts the following props:
Prop Name | Type | Default Value | Description |
---|---|---|---|
cursorVelocity |
Number | 0.5 |
The velocity of the cursor movement. |
followerVelocity |
Number | 0.1 |
The velocity of the follower movement. |
idleTiming |
Number | 1500 |
The time in milliseconds before the cursor is considered idle. |
showFollower |
Boolean | true |
Whether to show the follower cursor. |
showCursor |
Boolean | true |
Whether to show the main cursor. |
elementsToHover |
Array | ['a', 'button:not([disabled])', 'input:not([disabled])'] |
The elements that trigger hover state. |
<template>
<MagicCursor
:cursor-velocity="0.5"
:follower-velocity="0.2"
:idle-timing="2000"
:show-follower="true"
:show-cursor="true"
:elements-to-hover="['a', 'button', 'input']"
/>
</template>
<script>
import MagicCursor from 'vue-magic-cursor';
export default {
components: {
MagicCursor
}
};
</script>