TS & JS Library for adaptive precision cursor for the web. Releases will come out soon! Meanwhile, check out the demo site:

Overview

Haha, cool cursor go brrrr...

NPM Version License: GPL-3.0 Website shields.io

Table of Content
  1. What is this?
  2. Installation & Setup
  3. Usage
  4. Known issues
  5. Troubleshooting
  6. Contributing
  7. License

What is this?

BetterPointer is a JS/TS package that simulates adaptive precision on a webpage with the intention of making buttons and other elements on a website/webapp easier to interact with.

It was largely inspired by the ipadOS cursor, but is implemented in such a way that allows for greater visual and behavioral customization.

You can try the pointer out at: https://lemonorangewastaken.github.io/BetterPointer/


Getting Started

This section will cover what you need to setup and start using your cursor.

Installation

Note: if you are using JS without NPM, a cdn accessible min.js file is not yet avaiable, but should hopefully be soon.

This package is available on NPM, and currently supports TS and JS. To install, setup an npm project by running:

npm init -y

Then, install the package by running

npm i betterpointer

Please note: this package only works with frontend JS/TS, and will not work on NodeJS/TS. If you need instructions on how to setup npm libraries for frontend JS, please read this article.

Setup

To setup the cursor in your project, create an empty div under the body tag of your HTML file, and give it a unique id. Ex:
<body>
    <div id="some-unique-id"></div>
    <!-- rest of your document... -->
</body>

Make sure that there are no styles applied to this div, either in the inline HTML or in a linked CSS sheet.

In your JS/TS file, import the package:

import cursor from "betterCursor";

Then, create an instance of the cursor. This is what will be used to control your cursor, such as toggling light and dark mode.

const myCursor = new cursor("some-unique-id");

You may also pass in a configuration object, like so:

const config = {
    size : "50px",
    mass : 125
};

const myCursor = new cursor("some-unique-id", config);

Configurable parameters:

Key Default Units Descritpion
size "24px" - The default size of the cursor.
mass 75 - How "heavy" the cursor feels.
trackingPeriod 50 ms The period in which the cursor will check for elements to snap on to.

Usage

This section will cover how to utilize your cursor to its full potential.

Cursor controls

These are functions that you can use to control the cursor's appearance and behavior.


Setting the cursor's dark/light appearance

If your site contains a toggleable dark theme or you need to forcibly change the light/dark appearance of your cursor, you may use these two functions to do so:

myCursor.setDark();   // make the cursor visible in dark theme
myCursor.setLight();  // make the cursor visible in light theme

Note: setDark() will set the cursor to a translucent white color and is meant to be used in a dark themed environment. It does not make the cursor itself dark! The same logic applied to setLight() as well.


Forcibly morphing/snapping the cursor

Doing this is not reccomended, as it is still in development and can act buggy. But if, for whatever reason, you need to morph/snap the cursor to an element, you may use this command to do so:

// morph the cursor into text mode,
// and apply this effect in reference of myElmnt
setShape("text", myElmnt, false, 15);

Here's what each of the parameter means (in order):

Name Type Optional Default Descritpion
shape String - Shape that the cursor should morph to
elmnt HTMLElement currentHoveringElmnt The reference element (to get parameters such as size and line height from)
hideCursor Boolean false Whether or not to hide the cursor
snapCoef Number 10 The larger the number is, the more the element will stick to the cursor.

All the shapes that are available (if the shape doesn't match any in this table, the cursor will just return to normal):

Shape Description
Text Morph your cursor into a text selection shape, with height matching the line height
input Similar to the text selection, except there will be a bit of Y snapping in the text input box
button Complete snap onto an element in the X and Y direction

Element Settings

Your cursor will only morph/snap onto elements you specified. So if you have a button but didn't specify for the cursor to snap onto it, it will be ignored as a normal element.

BetterPointer uses custom HTML attributes to identify target elements. Some examples are provided below:

<!-- Morph the cursor into text selection mode -->
<p snaptext> Lorem ipsum dolor sit amet... </p>

<!-- Snap the cursor onto a button -->
<button snapbutton> Click Me! </button>

Some of attributes available to configure cursor snap target:

Attributes Snap To Elmnt Description
snaptext morphs the cursor into the text's shape.
snapinput snaps the cursor into the input box.
snapbutton snaps the cursor to the shape of the button (works on different elements too).
bigsnapbutton Same as snapbutton, but hides the cursor and is more sticky.

Some of the attributes available to configure cursor behavior:

Attributes Example Description
growth "10px" Enlarges the cursor by specified amount (Ex: 10px).

Note: in snapbutton and bigsnapbutton mode, the cursor will morph to the element's bounding box width, height, and corner radius. It is advised to add some padding and corner radius to your elements for an optimal snapping effect.

Known issues

Here are some known issues about the library so far:

  1. Safari absolutely refuses to work with the web (as well as Internet Explorer).
  2. Does not work well with transitioning elements
  3. Random errors in the console sometimes
  4. Immense lag on opening up dev tools
  5. Poor behavior with mouse on demo page

Troubleshooting

If your cursor does not show up, please check if there is any elements overlaid on top of it that has a z-index over 999999. If there is some other errors, please file an issue report here, or make a pull request.

Contributing

You can't yet, but if you would like to work on it for some reason, please contact me at [email protected]

License

BetterPointer is licensed under the GPL-3.0 license, please respect it.

You might also like...

A mobile web application to check the data on the total covid19 confirmed cases and deaths, check data for all countries with recorded cases.

This is a mobile web application to check the data on the total covid19 confirmed cases and deaths, check data for all countries with recorded cases. It also has a details page to check for the statistics for each region/state if available.

Jul 30, 2022

Spiner bot to buy and sell tokens on ETH and ERC compatible chains as soon as liquidity is added and trade is enabled.

Spiner bot to buy and sell tokens on ETH and ERC compatible chains as soon as liquidity is added and trade is enabled.

An open-source defi sniper. open-sniper is free to download. Premium Services Now Available While open-sniper is free and open-source, if you want the

Apr 21, 2022

🪵 Aggressively find a packages changelog (or releases) between versions.

🪵 changelogd Aggressively find a packages changelog (or releases) between versions. Status: Early Access Please report any issues 🐛 Made possible by

May 10, 2022

tooldb is a (soon) massive collection of frameworks and tools. It's build on Flowbite, Next.js, Tailwind CSS and uses Supabase.

tooldb is a (soon) massive collection of frameworks and tools. It's build on Flowbite, Next.js, Tailwind CSS and uses Supabase.

tooldb is a (soon) massive collection of frameworks and tools. It's build on Flowbite, Next.js, Tailwind CSS and uses Supabase.

Jul 14, 2022

Open-source CD platform that helps developers to deliver applications efficiently by simplifying software releases and operations in any environment.

Open-source CD platform that helps developers to deliver applications efficiently by simplifying software releases and operations in any environment.

dyrector.io - The open source internal delivery platform Overview dyrector.io is an open-source internal delivery platform that helps developers to de

Jan 3, 2023

A web applicaton called 'MOVTIME' where you can come to stream movies by consuming the TMDB movie API

End result Click here : https://movtime-movie-app.netlify.app/ Figma design File Click here: https://www.figma.com/file/4IbpmTU6jtpRKdpbFmt4i8/Web-Des

Nov 11, 2022

A powerful javascript library to create amazing and smooth effects for the mouse cursor on your website.

A powerful javascript library to create amazing and smooth effects for the mouse cursor on your website.

Cuberto Mouse Follower A powerful javascript library to create amazing and smooth effects for the mouse cursor on your website. Dependencies GSAP v3 (

Dec 30, 2022

Team-8 E-Commerce Project for egFWD & Sprints industry exposure program You can check the live demo Here

Team-8 E-Commerce Project Team-8 E-Commerce Project for egFWD & Sprints industry exposure program You can check the live demo Here Table of Contents P

Jun 16, 2022

The Awesome estate web application displays a list of apartments that were provided by local data. The users can check out the featured and recent apartments. Also, the user can click the house to get the details of the selected house.

The Awesome estate web application displays a list of apartments that were provided by local data. The users can check out the featured and recent apartments. Also, the user can click the house to get the details of the selected house.

Awesome Estate The Awesome estate web application displays a list of apartments that were provided by local data. The users can check out the featured

Sep 14, 2022
Releases(V1.0.2)
  • V1.0.2(May 16, 2022)

    This should hopefully be the first usable release. V1.0.2 now uses a JS backend to handle most of the transitioning, which makes it usable on Safari.

    Install this package on NPM by running: npm i betterpointer Documentation is in this repo's README

    Still no min.js lib yet, that will have to wait a little bit 😬. Sorry!

    Source code(tar.gz)
    Source code(zip)
Owner
LemonOrange
Fullstack & AI dev but more focused on DNN's and frontend UI & UX.
LemonOrange
This is a simple javascript file that gives you control over the browser cursor, alowing for fully animated cursors using CSS's cursor functionality.

animatedWebCursors.js This is a simple javascript file that gives you control over the browser cursor, alowing for fully animated cursors using CSS's

alienmelon 32 Dec 25, 2022
Check in, check the weather, Check out.

☀️ Just-Weather ??️ Hi, Welcome! Just Weather is a Web App designed for Fast Real-Time Weather queries in combination with well Thought Out Visual Des

Miguel Ángel 6 Aug 7, 2022
💅 A ready-to-go with a well-thought-out structure Electron app boilerplate with ReactJS, TypeScript, CSS / SASS modules, SWC, Eslint, Prettier, GitHub Action releases and more.

Electron App ??  A ready-to-go with a well-thought-out structure Electron app boilerplate with ReactJS, TypeScript, CSS / SASS modules, SWC, Eslint, P

Dalton Menezes 155 Dec 29, 2022
Fast and robust triangle-triangle intersection test with high precision for cross and coplanar triangles based on the algorithm by Devillers & Guigue.

fast-triangle-triangle-intersection Fast and robust triangle-triangle intersection test with high precision for cross and coplanar triangles based on

Technology and knowledge for interaction 10 Nov 15, 2022
The app helps you to add todo items to your list, mark completed ones and also delete finished items. Its a handy tool for your day today activies. Check out the live demo.

Todo List App The app helps you to add todo items to your list, mark completed ones and also delete finished items. Its a handy tool for your day toda

Atugonza ( Billions ) Joel 14 Apr 22, 2022
I made countdown birthday and fireworks animation using HTML Canvas, CSS, JS. The fireworks animation gonna come out once the countdown is finished or in other words, "Birthday Time".

Countdown-Birthday-Fireworks-Animation I made countdown birthday and fireworks animation using HTML Canvas, CSS, JS. The fireworks animation gonna com

Mahardika Bayu S.B 19 Dec 31, 2022
Library to download binary files from GitHub releases detecting the correct platform.

Dbin TypeScript library to download binary files from GitHub releases detecting the correct platform. Example: import dbin from "https://deno.land/x/d

Óscar Otero 7 Oct 4, 2022
Grupprojekt för kurserna 'Javascript med Ramverk' och 'Agil Utveckling'

JavaScript-med-Ramverk-Laboration-3 Grupprojektet för kurserna Javascript med Ramverk och Agil Utveckling. Utvecklingsguide För information om hur utv

Svante Jonsson IT-Högskolan 3 May 18, 2022
Hemsida för personer i Sverige som kan och vill erbjuda boende till människor på flykt

Getting Started with Create React App This project was bootstrapped with Create React App. Available Scripts In the project directory, you can run: np

null 4 May 3, 2022
Kurs-repo för kursen Webbserver och Databaser

Webbserver och databaser This repository is meant for CME students to access exercises and codealongs that happen throughout the course. I hope you wi

null 14 Jan 3, 2023