Replaces native cursor with custom animated cursor.

Overview

Animated Cursor

A pure JS library to replace native cursor with a custom animated cursor.

Check out the Demo

Contents

  1. πŸ“Œ Features
  2. 🎯 Quickstart
  3. 🧬 Options
  4. πŸ€– Commands
  5. πŸ•ΉοΈ Usage
  6. 🎨 Cursor Types
  7. πŸ““ Notes
  8. πŸ“… To Dos

πŸ“Œ Features

  • Dependency free, pure JavaScript library.
  • Replaces native Cursor with custom animated cursor.
  • Cursor is comprised of inner dot and outer circle with trailing animation. Cursor elements inversely scale on click and hover.
  • Options to customize color, sizes, scaling percentages.
  • Performant cusor animation
  • Cursor is just a dom element that you can further style (ie: add border to outer cursor)
  • Hybrid NPM module, works with import and require

More the specifically, the cursor is made of

  • An inner dot (cursorInner)
  • An outer, outlining circle (cursorOuter), with slight opacity based on the inner cursor's color
  • A slight trailing animation of the outer outline
  • An inversely scaling effect between the inner and outer cursor parts on click or link hover
  • Outer cursor can also be just a border to create a Donut style cursor.
  • Outer cursor can have a blend-mode applied for an exlusion effect over hovered text / elements.

🎯 Quickstart

1. Install from NPM

npm i animated-cursor

2. Create Cursor Markup

<div id="cursor">
  <div id="cursor-outer"></div>
  <div id="cursor-inner"></div>
</div>

3. Init Cursor

Import and initialize. Example is using defaults but accepts an options paramter (see below)

import AnimatedCursor from 'animated-cursor'

// Using just default options 
const ac = AnimatedCursor()

ac.init()

🧬 Options

AnimatedCursor() accepts a single options param, which supports the following properties:

Option Type Description Default
cursorInnerSelector String Selector name of inner cursor element. #cursor-inner
cursorOuterSelector String Selector name of outer cursor element. #cursor-outer
useRequiredStyles Boolean If lib should add required styles to element. true
hideNativeCursor Boolean If native cursor should be hidden via internal method adding inline styles to html and body. true
color String Hex value of desired color. #D3245C
outerAlpha Number Alpha transparency level of outer cursor (0 - 1). 0.3
outerBorderSize Number Applies a border to the outer cursor. 0.3
hasOuterBlendMode Boolean Applies a blend-mode to the outer cursor 0.3
size Object Defines inner size.inner and Outer size.outer cursor sizes size: { inner: 8, outer: 40 }
hoverScale Object Defines amounts inner/outer cursors scale on hover hoverScale: { inner: 0.75, outer: 1.5 }
clickScale Object Defines amounts inner/outer cursors scale on click clickScale: { inner: 1.5, outer: 0.13 }
trailingSpeed Number Speed of outer cursor's lerp'd trailing animation 0.2
clickables Array Array of clickable elements. d ['a', 'input[type="text"]', 'input[type="email"]', 'input[type="number"]', 'input[type="submit"]', 'input[type="image"]', 'label[for]', 'select', 'textarea', 'button', '.link']

πŸ€– Project Commands

Install Project Deps

npm i

Build

npm run build

Builds src with microbundle to the various common js patterns.

Run Dev

npm run dev

Dev has microbundle begin watching / building the files, while also running the demo project via Parcel, which imports from the local src directory.

Run Demo

npm run demo:start

Runs the demo project via Parcel.

Lint

npm run lint


πŸ•ΉοΈ Usage

Cursor markup

The cursor is created from 2 dom elements for the inner and outer parts.

<div id="cursor">
  <div id="cursor-outer"></div>
  <div id="cursor-inner"></div>
</div>

You can use the default selector names (shown above), or pass your own via the options, cursorInnerSelector and cursorOuterSelector

const opts = {
  cursorInnerSelector: '#js-cursor-outer`
  cursorOuterSelector '#js-cursor-inner',
  ....
}

Init Cursor

import AnimatedCursor from 'animated-cursor'

// cursor options
let acOptions = {
  color: '#0ff',
  outerAlpha: 0.25,
  size: { 
    inner: 8, 
    outer: 38 
  },
  hoverScale: {
    inner: 0.5,
    outer: 1.4
  },
  clickScale: {
    inner: 1.4,
    outer: 0.1
  }
}

// Create Cursor instance
const cursor = AnimatedCursor(acOptions)

// Init Cursor
cursor.init()

Use require

AnimatedCursor is a hybrid npm module, so it supports both import and require.

So, you can also require to lib like so:

const AnimatedCursor = require('animated-cursor')

const cursor = AnimatedCursor(opts)
cursor.init()

🎨 Cursor Types

You can use the options to create various cursor types / styles. (At some point I might organize cursor types as presets.)

Create a Donut Cursor

The outerBorderSize option applies a border to the outer cursor. You can leverage this to create a Donut style cursor:

  1. Set outerAlpha to 0s (or almost 0),
  2. Provide a numeric value for outerBorderSize lkkklllklwhere the outer cursor is a ring, apply a border to the outer cursor and set the outerAlphd0 (or close to 0)
// Options to create a Donut cursor
let donutOpts = {
  color: '#0ff',
  outerAlpha: 0,
  outerBorderSize: 3
}

Check out the Donut Cursor Demo


Create a Blend-mode Cursor

You can create a neat Blend-mode cursor that filters the hovered text through the cursor. This probably works best with White / Black cursors.

  1. Set hasOuterBlendMode: true,
  2. Set outerAlpha to 1 or close to 1.
  3. Probs use a cursor color like #fff or #000.

Note, make sure your inner and outer cursor elements are wrapped inside a parent (as show in the examples) as the parentElement of outer cursor is targets for the blend-mode filter. lkkklllklwhere the outer cursor is a ring, apply a border to the outer cursor and set the outerAlphd0 (or close to 0)

// Options to create a blend-mode cursor.
// Cursor is white, page background-color is dark.
 let blendOpts = {
    hasOuterBlendMode: true,
    color: '#fff',
    outerAlpha: 1
 }

Check out the Blend-mode Cursor Demo

πŸ““ Notes

useRequiredStyles

For the cursors to work, some styles are require for positioning, radius, pointer-events, stating opacity, and transitions. By default, AnimatedCursor adds these styles via JS, directly on the cursor elements. If you'd prefer, you can stop the lib from adding those inline styles in favor of css. Just set useRequiredStyles: false and provide your own css to the inner/outer cursor selectors.

This action would also allow you to modify the transition speed and easings of the cursors scaling (transform) animation.

#cursor-inner,
#cursor-outer {
  pointer-events: none;
  position: fixed;
  border-radius: 50%;
  opacity: 0;
  transform: translate(-50%, -50%);
  transition: opacity 0.3s ease-in-out, transform 0.3s ease-in-out; 
}

hideNativeCursor

The hideNativeCursor option is a bool that determins if native cursor should be hidden by adding inline styles to the html and body tags. Set to false if you want to maintain the native cursor, or if you'd rather hide the cursor with css.


πŸ“… To Dos

  • Provide ability to create Donut style cursor
  • Add a demo for Donut-style cursor
  • Make clickables an option.
  • Make hybrid npm module to support import and require.
  • Make hiding native cursor an option..
  • Limit to non touch or non mobile devices.
  • Provide a destory method
  • Maybe make different cursor types available as presets?
You might also like...

Custom Gutenburg blocks to add custom functionalities to your WordPress site. Brought to you by Arif Khan with 3

Custom Gutenburg blocks to add custom functionalities to your WordPress site. Brought to you by Arif Khan with <3

Gutpress(WordPress Gutenburg Block Plugin) Custom Gutenburg blocks to add custom functionalities to your WordPress site. Brought to you by Arif Khan w

Nov 23, 2022

Custom navigations for Solid written in Typescript. Implement custom page transition logic and ✨ animations ✨

solid-custom-navigation Get, Set, Go! Custom navigations for Solid, written in Typescript. Implement custom page transition logic and ✨ animations ✨ .

Nov 27, 2022

Create Bootstrap 5 Modal Box using JavaScript with custom title, description, button labels and custom YES button callback

Create Bootstrap 5 Modal Box using JavaScript with custom title, description, button labels and custom YES button callback

Dynamic BS5 Modal Box Create Bootstrap 5 Modal Box using JavaScript with custom title, description, button labels and custom YES button callback Insta

Oct 23, 2022

A powerful javascript library to create amazing and smooth effects for the mouse cursor on your website.

A powerful javascript library to create amazing and smooth effects for the mouse cursor on your website.

Cuberto Mouse Follower A powerful javascript library to create amazing and smooth effects for the mouse cursor on your website. Dependencies GSAP v3 (

Dec 30, 2022

TS & JS Library for adaptive precision cursor for the web. Releases will come out soon! Meanwhile, check out the demo site:

Haha, cool cursor go brrrr... Table of Content What is this? Installation & Setup Installation Setup Usage Cursor controls Element settings Known issu

Nov 24, 2022

Planets fact site with animated solar system built with ReactJS.

Planets fact site with animated solar system built with ReactJS.

Frontend Mentor - Planets fact site Table of contents Overview Intro The challenge Links My process Built with Features Setup Useful resources Overvie

Jan 1, 2023

A javascript library to generate animated wavy text!

A javascript library to generate animated wavy text!

Wavy Text Animation Library A JavaScript Library which allows you to animate infinite words in an infinite loop in a modern wavy way! Options Vanilla

Oct 9, 2022

Animated Select Component (React)

Spring Chain We built a custom select component with a menu with animations and beautiful gradients and a glassy style, is called "Spring Chain" becau

Feb 6, 2022

Animated sprite hook for react-three-fiber

use-animated-sprite Animated sprite hook for react-three-fiber Dependencies npm install @react-three/drei @react-three/fiber react three Installation

Dec 4, 2022
Comments
  • New option: hasOuterBlendMode

    New option: hasOuterBlendMode

    Added hasOuterBlendMode option which allows you create a blend-mode style cursor.

    • Updated ReadMe / Docs
    • Create new demo for blend.
    • Refactored how styles are added
    opened by stephenscaff 0
Owner
Stephen Scaff
I design and develop digital things. Currently running a Design Technology team at eBay. Before that I was at Alexa (Amazon). Before that, Urban Influence.
Stephen Scaff
Kuldeep 2 Jun 21, 2022
Given an object and a property, replaces a property descriptor (or deletes it), and returns a thunk to restore it.

Given an object and a property, replaces a property descriptor (or deletes it), and returns a thunk to restore it.

Jordan Harband 7 Apr 20, 2022
Replaces the default Strapi WYSIWYG editor with a customized build of CKEditor 5 html editor packed with useful plugins.

CKEditor 5 for Strapi Replaces the default Strapi WYSIWYG editor with a customized build of CKEditor 5 packed with useful plugins. ?? Get Started Feat

null 39 Jan 2, 2023
Replaces Youtube Chat with Destiny.gg chat.

A lightweight extension that replaces the native Youtube Live chat with an embeded destiny.gg chat. Note: This is in no way affiliated with Destiny.gg

Daniel Alas 8 Jul 27, 2022
A Powerful and Elegant "alert" library for JavaScript that replaces that boring alert style of Javascript.

A Powerful , Elegant and fully customizable "alert" library using JavaScript that replaces that boring style of alert. Installation Place the below sc

Cosmogic 11 Aug 10, 2021
A browser/Chrome extension that replaces Leftist #trigger words with "bad thing" and "current bad thing". Inspired by Tim Pool.

BadThings browser/Chrome extension replaces Leftist #trigger words with 'bad things' and 'current bad thing'. Quickstart This project uses React 18 an

Cale McCollough 2 Sep 5, 2022
Next-level academia! Repository for the Native Overleaf project, attempting to integrate Overleaf with native OS features for macOS, Linux and Windows.

Native Overleaf Overleaf is a fantastic webtool for writing and cooperating on LaTeX documents. However, would it not be even better if it were to beh

Floris-Jan Willemsen 40 Dec 18, 2022
logseq custom.js and custom.css utilities : resize query table columns, hide namespaces...

logseq-custom-files custom.js and custom.css utilities for Logseq. current version v20220331 query table view : add handles on the query table headers

null 44 Dec 7, 2022
This experimental library patches the global custom elements registry to allow re-defining or reload a custom element.

Redefine Custom Elements This experimental library patches the global custom elements registry to allow re-defining a custom element. Based on the spe

Caridy PatiΓ±o 21 Dec 11, 2022
Ready to manipulate partitions file? Create a custom partition, apply custom security system, hide the partition and share your hidden data on the www

Paranoia ?? Ready to manipulate partitions file? Create a custom partition, apply custom security system, hide the partition and share your hidden dat

Alice Snow 3 Dec 29, 2022