
ipad-mouse

Mouse effect hacking of iPad in browser that can be used in any frameworks
Install
-
NPM
npm install ipad-cursor --save
-
CDN
<script src="https://unpkg.com/ipad-cursor@latest" />
See ipad-cursor.oooo.so for more details.
Usage
Basic usage
Apply data-cursor
attribute to the element you want to add the effect.
data-cursor="text"
: text cursordata-cursor="block"
: block cursor
<div data-cursor="text">Text Cursor</div>
<div data-cursor="block">Block Cursor</div>
After your dom loaded, call initCursor
to start the effect. You may need to call initCursor
when dom updated.
import { initCursor } from 'ipad-cursor'
initCursor()
⚠️ Notice: As so far, you need to manage when to updateCursor
yourself. Make sure to call updateCursor
after dom updated.
In the future, there maybe a better way to handle this, see Roadmap for more details.
Principle
When initCursor
called, it will remove default cursor, and generate a fake cursor use div
element. Then listen mousemove
event, and move the fake cursor to the mouse position.
After init finished, it will call updateCursor
method, scan element with data-cursor
attribute, detect the cursor type, and add event listener to the element.
When mouse enter the element, apply styles.
API
initCursor(cfg)
see Config for more details.
Init cursor, remove default cursor, and generate a fake cursor use div
element. Then listen mousemove
event, and move the fake cursor to the mouse position.
updateCursor
Scan element to observe hover event, and apply styles, as well as remove unused element's event listener.
disposeCursor
Remove fake cursor, and remove all event listener, recover default cursor.
updateConfig(cfg)
Update config, see Config for more details.
customCursorStyle(style)
Create style string that can be used as data-cursor-style
attribute.
This method is used for better type hinting.
Config
It is recommended to see index.d.ts in the npm package.
type MaybeSize = string | number;
type MaybeDuration = string | number;
type MaybeColor = string;
export interface IpadCursorConfig {
adsorptionStrength?: number;
className?: string;
normalStyle?: IpadCursorStyle;
textStyle?: IpadCursorStyle;
blockStyle?: IpadCursorStyle;
blockPadding?: number | "auto";
}
export interface IpadCursorStyle {
width?: MaybeSize;
height?: MaybeSize;
radius?: MaybeSize;
durationBase?: MaybeDuration;
durationPosition?: MaybeDuration;
durationBackdropFilter?: MaybeDuration;
background?: MaybeColor;
border?: string;
zIndex?: number;
scale?: number;
backdropBlur?: MaybeSize;
backdropSaturate?: string;
}
Roadmap
Showcase