0.2.4 • Published 3 years ago

custcur v0.2.4

Weekly downloads
423
License
MIT
Repository
github
Last release
3 years ago

custcur

npm

A lightweight, highly customizable cursor event framework for the web.

Installation

Via CDN

<script src="https://unpkg.com/custcur@0.2.4/dist/bundle.js"></script>

Via Yarn or NPM

  1. Install in terminal:
yarn add custcur
npm i custcur
  1. Initialize a custom cursor with default options:
import CustCur from 'custcur';

const cursor = new CustCur();

Usage

You can pass an options object as a parameter to the constructor in order to overwrite defaults:

const options = {
	target: document.querySelector('.section-1'),
	tag: 'div',
	classes: {
		base: 'cursor',
		hover: 'cursor-hover',
		click: 'cursor-click',
	},
};

const cursor = new CustCur(options);

You can also assign an existing html element as your custom cursor node:

const cursor = new CustCur({
	target: window,
	node: document.querySelector('.custom-cursor'),
});

The tag and classes.base parameters will get completely ignored if a node is present. Nevertheless the specified node will get the defined event classes when an related event occures within the defined target.

Available Options

PropertyTypeDescriptionDefault
targetNodeParent Element for custom cursor.window
nodeNode?Custom cursor node element. If not present, CusCur will create a node of the specified tag and assign the defined classname.null
hoverablesArrayArray of css-selectors or node elements within the specified target that should trigger the cursor's hover event.['a', 'button']
hideDefaultBooleanDetermine if the system's default cursor should be hidden when inside of specified target.true
classes.baseStringSpecifies the cursor's base classname.'cc-cursor'
classes.hoverStringSpecifies a classname for the cursor's hover state.'cc-hover'
classes.clickStringSpecifies a classname for the cursor's click state.'cc-click'
onEnterMethodListen for mouseover event on specified target.(e)=>{}
onLeaveMethodListen for mouseout event on specified target.(e)=>{}
onMoveMethodListen for mousemove event on specified target.(e)=>{}
onClickMethodListen for mousedown event within specified target.(e)=>{}
onClickReleaseMethodListen for mouseup event within specified target.(e)=>{}
onHoverEnterMethodListen for mouseover event on all specified hoverables.(e)=>{}
onHoverLeaveMethodListen for mouseout event on all specified hoverables.(e)=>{}

...? type can be null.

Available Methods

MethodDescription
State
cursor.enable()Enable custom cursor along with all event listeners.
cursor.disable()Disable custom cursor and remove all event listeners.
cursor.toggle()Toggle between enabled and disabled state.
Events
cursor.onEnter(fn)Register a callback function for mouseover event on specified target.
cursor.onLeave(fn)Register a callback function for mouseout event on specified target.
cursor.onMove(fn)Register a callback function for mousemove event on specified target.
cursor.onClick(fn)Register a callback function for mousedown event within specified target.
cursor.onClickRelease(fn)Register a callback function for mouseup event within specified target.
cursor.onHoverEnter(fn)Register a callback function for mouseover event on all specified hoverables.
cursor.onHoverLeave(fn)Register a callback function for mouseout event on all specified hoverables.

Each event callback will overwrite it's related event method from the initial options object.

0.2.4

3 years ago

0.2.3

3 years ago

0.2.2

3 years ago

0.2.1

3 years ago

0.2.0

3 years ago

0.1.8

3 years ago

0.1.7

3 years ago

0.1.6

3 years ago

0.1.2

3 years ago

0.1.3

3 years ago

0.1.5

3 years ago

0.1.1

3 years ago

0.1.0

3 years ago

0.0.9

3 years ago

0.0.8

3 years ago

0.0.5

3 years ago

0.0.7

3 years ago

0.0.6

3 years ago

0.0.1

3 years ago

0.0.3

3 years ago

0.0.2

3 years ago

0.0.4

3 years ago

1.0.1

3 years ago

1.0.0

3 years ago