Getting Started
Download
Via npm
npm install cotton
Via CDN
<script src="https://cdn.jsdelivr.net/gh/fluffy-factory/magnet-mouse@latest/lib/magnet-mouse.min.js"></script>
Manual download
Installation
ES modules
After Download the files from npm, all you need is typing the following code :
import Cotton from 'cotton'
Script tag include
Simply download (or using CDN) and include with a script tag.
<script src="cotton.js"></script>
Basic Usage
HTML
Create an element that you would like to animate.
<div id="#cotton-cursor"></div>
CSS
Style your element.
If you want to make a mouse-following element, you have to set the position property as fixed.
#cotton-cursor {
position: fixed;
z-index: 9;
width: 20px;
height: 20px;
border-radius: 50%;
pointer-events: none;
background-color: #f9cabc;
transform: translate(-20px, -20px); /* move out from window before cotton init */
}
JavaScript
Initialize Cotton in JavaScript.
const cottonCursor = new Cotton('#cotton-cursor')