![Oracle Drags Its Feet in the JavaScript Trademark Dispute](https://cdn.sanity.io/images/cgdhsj6q/production/919c3b22c24f93884c548d60cbb338e819ff2435-1024x1024.webp?w=400&fit=max&auto=format)
Security News
Oracle Drags Its Feet in the JavaScript Trademark Dispute
Oracle seeks to dismiss fraud claims in the JavaScript trademark dispute, delaying the case and avoiding questions about its right to the name.
animated-cursor
Advanced tools
A pure JS library to replace native cursor with a custom animated cursor.
import
and require
cursorInner
)cursorOuter
), with slight opacity based on the inner cursor's colornpm i animated-cursor
<div id="cursor">
<div id="cursor-outer"></div>
<div id="cursor-inner"></div>
</div>
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()
To include via CDN, find the latest UMD version at https://unpkg.com/animated-cursor and include via script tag, like so:
<script src="https://unpkg.com/animated-cursor@1.1.1/dist/index.umd.js"></script>
then call and init:
const ac = window.animatedCursor()
ac.init()
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 |
cursorInnerStyles | Object | Adds inline styles to Inner cursor | null |
cursorOuterStyles | Object | Ads inline styles to Outer cursor | null |
hasRequiredStyles | 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 X | 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. | ['a', 'input[type="text"]', 'input[type="email"]', 'input[type="number"]', 'input[type="submit"]', 'input[type="image"]', 'label[for]', 'select', 'textarea', 'button', '.link'] |
npm i
npm run build
Builds src
with microbundle
to the various common js patterns.
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.
npm run demo:start
Runs the demo project via Parcel.
npm run lint
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',
....
}
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()
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()
You can use the options to create various cursor types / styles. (At some point I might organize cursor types as presets.)
The outerBorderSize option applies a border to the outer cursor. You can leverage this to create a Donut style cursor:
outerAlpha
to 0
s (or almost 0),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
You can create a neat Blend-mode cursor that filters the hovered text through the cursor. This probably works best with White / Black cursors.
cursorInnerStyles
and cursorOuterStyles
that define mixBlendMode: 'exclusion'
backgroundColor
#fff
or #000
depending on page bg color.// Options to create a blend-mode cursor.
// Cursor is white, page background-color is dark.
let blendOpts = {
cursorInnerStyles: {
backgroundColor: 'var(--cursor-color)', // white
mixBlendMode: 'exclusion'
},
cursorOuterStyles: {
backgroundColor: 'var(--cursor-color)', // white
mixBlendMode: 'exclusion'
}
}
Check out the Blend-mode Cursor Demo
The options cursorInnerStyles
and cursorOuterStyles
pass inline styles directly to the cursor's inner / outer elements. This allows you to easily create custom and dynamic cursors. For example, you can simply pass css variables to define and update cursor colors, or you can create a Mixed Blend Mode-style cursor by passing mixBlendMode: 'exclusion'
.
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 hasRequiredStyles: 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;
}
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.
import
and require
FAQs
Create a custom, animated cursor in pure JS.
The npm package animated-cursor receives a total of 204 weekly downloads. As such, animated-cursor popularity was classified as not popular.
We found that animated-cursor demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
Oracle seeks to dismiss fraud claims in the JavaScript trademark dispute, delaying the case and avoiding questions about its right to the name.
Security News
The Linux Foundation is warning open source developers that compliance with global sanctions is mandatory, highlighting legal risks and restrictions on contributions.
Security News
Maven Central now validates Sigstore signatures, making it easier for developers to verify the provenance of Java packages.