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()
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 |
color | String | Hex value of desired color. | #D3245C |
outerAlpha | String | Alpha transparency level of outer cursor (0 - 1). | 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. | ['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 options = {
color: '#fff',
outerAlpha: 0.3,
trailingSpeed: 0.2,
cursorSize: { inner: 8, outer: 38 }
}
const ac = AnimatedCursor(options)
ac.init()
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.
#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;
}
FAQs
Create a custom, animated cursor in pure JS.
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.