Git Product home page Git Product logo

cursor-effects's Introduction

90s Cursor Effects

"Knowing the codes" used to be all the rage, I want to bring a few back.

A repo of the old effects that inspired creativity and the desire to learn at least a little code around the world. Modernised so they're a little more efficient, and just as annoying (and twice as fun) as they were before. Have a play here.

The current effects are:

  • Rainbow Cursor
  • Emoji Rain
  • Elastic Emoji
  • Ghost Following
  • Trailing Cursor
  • Text Flag Cursor
  • Following Dot
  • Bubbles Particles
  • Snowflake Particles
  • Fairy Dust
  • Clock Cursor
  • Character Cursor

How to Set Up Locally/Develop

  1. First the packages request (this is only rollup, which code compilation) with npm install
  2. npm run watch This will compile the src in the dist folder that index.html is looking for and update it when changes are made. You can then go to index.html in the web browser of your choice.

How to Use

You need to include the following script tag in your webpage (see next section if you want to use this package via npm). And then, once the script is loaded you'll be able to add the effects to the page

<script src="https://unpkg.com/cursor-effects@latest/dist/browser.js"></script>

Alternatively you can use a type="module" script on newer browsers with a import statement, if you are using the esm module you will import the cursor specific to your needs, rather than having to use the cursoreffects.x style.

<script type="module">
  import { fairyDustCursor } from "https://unpkg.com/cursor-effects@latest/dist/esm.js";

  new fairyDustCursor();
</script>

And then create a new instance of its type in your JavaScript. The script will create the canvas that is used, so nothing else is really needed.

window.addEventListener("load", (event) => {
  new cursoreffects.ghostCursor();
});

You can also target specific elements, to have the canvas appear inside those, for example:

const targetElement = document.querySelector("#ghost");
new cursoreffects.ghostCursor({ element: targetElement });

To remove the effect, you can call destroy on it.

// Create
let cursorEffect = new ghostCursor();

// Destroy
cursorEffect.destroy()

or you can use NPM

npm install cursor-effects
import { emojiCursor } from "cursor-effects";
new emojiCursor({ emoji: ["๐Ÿ”ฅ", "๐Ÿฌ", "๐Ÿฆ†"] });

Specific Customization

A few of these have custom options as well (if you are interested in more options, opening an issue or PR is the way to go).

rainbowCursor

You can change the colors, size and length in rainbowCursor

new cursoreffects.rainbowCursor({
  length: 3,
  colors: ["red", "blue"],
  size: 4,
});

springyEmojiCursor

You can change the emoji in springyEmojiCursor's emoji with the emoji a single string emoji.

new cursoreffects.springyEmojiCursor({ emoji: "๐Ÿคทโ€โ™‚๏ธ" });

fairyDustCursor

You can change the emoji in fairyDustCursor's colors with the colors option (an array of colors)

new cursoreffects.fairyDustCursor({
  colors: ["#ff0000", "#00ff00", "#0000ff"],
});

emojiCursor

You can change the emoji in emojiCursor's emoji with the emoji option (a list of emoji)

new cursoreffects.emojiCursor({ emoji: ["๐Ÿ”ฅ", "๐Ÿฌ", "๐Ÿฆ†"] });

textFlag

You can change the textFlag's text with the text option (String), and color of the text with the color option (hex)

 new textFlag({text: "test",color:["#FF6800"]});

Accessibility

The cursor won't display if the user's system accessibility settings have prefers-reduced-motion enabled.

trailingCursor

You can change the number of trail steps in trailingCursor with the particles option (a number), the rate of the trail with the rate option (a number between 0 and 1, default is 0.4), and the trailing cursor image with the baseImageSrc option (a URL or base64 string)

new cursoreffects.trailingCursor({particles: 15, rate: 0.8, baseImageSrc: "data:image/png;base64,iVB..."});

You can change the color of the following dot in followingDotCursor with the color option (hex)

new cursoreffects.followingDotCursor({ color: ["#323232a6"] });

characterCursor

Consider this cursor as an extension of the snowflake cursor, but instead of the snowflake emoji you can specify a list of characters and colors to use as well as defining how the character's velocity, rotation and scaling should change over the characters lifespan. For example to produce the same effect you see in the demo page, you would use this. (It will also do this by default, but this is a great way to experiement and play around with the effect)

new cursoreffects.characterCursor({ 
    element: document.querySelector("#character"), 
    characters: ["h", "e", "l", "l", "o"],
    font: "15px serif",
    colors: [
        "#6622CC",
        "#A755C2",
        "#B07C9E",
        "#B59194",
        "#D2A1B8",
    ],
    characterLifeSpanFunction: function() {
        return Math.floor(Math.random() * 60 + 80);
    },
    initialCharacterVelocityFunction: function() {
        return {
            x: (Math.random() < 0.5 ? -1 : 1) * Math.random() * 5,
            y: (Math.random() < 0.5 ? -1 : 1) * Math.random() * 5,
        }
    },
    characterVelocityChangeFunctions: {
      x_func: function(age, lifeSpan) {
        return (Math.random() < 0.5 ? -1 : 1)/30;
      },
      y_func: function(age, lifeSpan) {
        return (Math.random() < 0.5 ? -1 : 1)/ 15;
      },
    },
    characterScalingFunction: function(age, lifeSpan) {
        let lifeLeft = lifeSpan - age;
        return Math.max(lifeLeft / lifeSpan * 2, 0);
    },
    characterNewRotationDegreesFunction: function(age, lifeSpan) {
        let lifeLeft = lifeSpan - age;
        console.log(age, lifeSpan);
        return lifeLeft / 5;
    }
})

Note that none of these behavior changing options are required but in that case it will use similar physics to the snowflake and use the asterisk character instead.

License

MIT af, but if you're using the scripts a GitHub sponsorship or shouting me a coffee would always be appreciated :)

cursor-effects's People

Contributors

ajmeese7 avatar andrewpetz avatar cuppajoeman avatar ghostdevv avatar gndclouds avatar goldingking avatar kyle-koivukangas avatar noplanman avatar proxy-99 avatar rgwood avatar sheeit avatar skgrush avatar sophiekoonin avatar sylturner avatar tholman avatar toastal avatar ztf666 avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

cursor-effects's Issues

please set the license explicitly

Hi,

The readme.md file already states this project is under the MIT license but it is better to have a license file in place.

Great work.

particle resizing

how can I resize the sizes of the particles like fairy particles make them thinner and smaller?

unsolicited protip

nice project!

applying cursor: none to body makes trailing and ghost even better.

๐Ÿ‘‹

using the npm onMouseOver and onMouseLeave in React

I'm using this npm and it works great. The only thing I'm wondering is how to turn it on and off under the condition of whether a user's mouse is active or inactive on a certain element. So far, the function runs only if the mouse hovers over my element, but it does not go away onMouseLeave. I can't figure out how to disable to trailing mouse under conditions met. Thank you this is awesome!!!

import React, { useState, useEffect } from 'react';
import avatar from '../../assets/avatar.jpg';
import { fairyDustCursor } from 'cursor-effects';

export default function Avatar() {
  let [showAnimation, setShowAnimation] = useState(false);

  const toggleAnimation = () => {
    setShowAnimation(!showAnimation);
  };

  function handleCursor() {
    if (showAnimation === true) {
      fairyDustCursor({ colors: ['#ebfae0'] });
    } else if (showAnimation === false) {
      // i have tried returning here...setting length and size to 0 but nothings works so far :D 
    }
  }

  useEffect(() => {
    console.log(showAnimation);
    handleCursor();
  });

  return (
    <img
      onMouseOver={toggleAnimation}
      onMouseLeave={toggleAnimation}
      src={avatar}
      alt="apple memoji of a person with a medium skintone and shoulder length brown hair smiling"
    />
  );
}

Linux cursor does not match the default image

I'm not sure if this is something that is possible to fix, but on different desktop environments the cursor looks different, and thus the static data string in the ghost and trailing cursors does not match.

different default cursor example

I haven't heard of any API or similar that can detect what the user's cursor looks like and duplicate into a datastring that you can use, but I wanted to open this in case anybody out there has and could recommend it.

Toggle Cursor effects

I'm wondering if there is a way to toggle the cursor on and off. I like the clock cursor, brings some retro early 00s flair, but it also interfers with reading websites. I have a event listening for mousemove and if the main tag is in the :hover query selector results I would like to turn off the cursor.

Appearing under body

Im a bit of a newbie at website design, but I have a domain and hosting plan using hostinger, but when I try to use this via inserting it into the head, it shows beneath the body. Any ideas?
image
image

Have a problem with bootstrap 5

image

Twig


{% extends 'base.html.twig' %}

{% block title %}Hello Statistic!{% endblock %}

{% block navbar %}
    <div class="container-fluid">
        <div class="col-md-12">
            {% include('navbar.html.twig') %}
        </div>
    </div>
{% endblock %}

{% block body %}

    {% include('modals/datepicker.html.twig') %}
    {% include('modals/filtration.html.twig') %}
    
    <div class="container">
        <div class="row">
            <div class="col-md-12 mt-1 mt-md-2">
                <h1>There  will be overall statistic! Coming soon..</h1>
                {{ dump(TICKETS_Attributes) }}
            </div>
        </div>
    </div>

</div>
{% endblock %}

P.S. Possible, container and row class forcibly influence on cursor block

how about using typescript

Interesting library!

Hello, I am a heavy user of typescript, and i found that this library doesn't have ts support (neither written in ts, nor seems to have a type declaration package like @types/xxx).

I'd love to do the work, rewrite this interesting library into ts to provide better type support, and I'll do it and issue a pr this week if you're up to it

Some developers don't like seeing ts, so I want to ask your opinion here first.

Change snowflake color

Is it possible to change the snowflake color to white? I can't seem to figure it out.

New mousepointer idea: Baby Turtle

There should be a mouse pointer in the form of a Baby Turtle.

I've seen that pointer shape in a screenshot of an obscure 90s game first, created by Twitter user @blinry. I think it was somewhere in this thread

Too many particles are created when Chrome DevTools is opened

Hey I figured out, that if you open Chromes DevTools on a site, where your particle code is applied, there are too many particles being created.

I dont know why it happens but it does. Although it is not really a dealbreaker I thought that you may be interested in taking a look at it.

FIrefox 82.0a1. Cursor Effects using emojis are broken because weird BoundingBoxes

For snowFlake, emoji, and springyEmoji the drawImage call fails.
This is because the TextMetrics returned from measureText have bounding box values that add to zero.

TextMetrics
    actualBoundingBoxAscent: -3.843
    actualBoundingBoxDescent: 3.843
    actualBoundingBoxLeft: 10.5
    actualBoundingBoxRight: -10.5
    width: 21
      let measurements = context.measureText(emoji);
      let bgCanvas = document.createElement("canvas");
      let bgContext = bgCanvas.getContext("2d");

      bgCanvas.width = measurements.width;
      bgCanvas.height =
        measurements.actualBoundingBoxAscent +
        measurements.actualBoundingBoxDescent;

      bgContext.textAlign = "center";
      bgContext.font = "21px serif";
      bgContext.textBaseline = "middle";
      bgContext.fillText(
        emoji,
        bgCanvas.width / 2,
        measurements.actualBoundingBoxAscent
      );

The easier fix I found is just using the height for the width, but no idea how other browser would take that.
The ghostCursor is also broke for me, but I wasn't able to find out why.

Investigate/Improve mobile touch handling

Some of the touch handling, especially when within box rather than fullscreen is a little strange, it is never going to be perfect considering touch devices and mouse devices operate so differently, but explore if it could be improved on my own demo page

keep it going !

i love your idea! this is so beautiful! Can you create more cursor effects (like... sheeps?) ?????

change color without destroying first?

is there an option for followingDotCursor({ color: ["#323232a6"] }) that allows you to set a new hex code without destroying & creating a new cursor first?

Canvas has a height of 100vh and glitches after

Hi,

I'm not sure if I'm doing something wrong. I'm using characterCursor and the canvas size is always 100vh. After scrolling down, the effect starts glitching (letters do not dissapear). I've trie using fixed position on the canvas, but this did not solve the issue. Is there any way, how to solve this?

Regards

the library doesnt work as espected

I'm trying to add the effect to my svelt project, but the console say's this
This browser has prefers reduced motion turned on, so the cursor did not init
and here is how im trying to make it

import { onMount } from 'svelte';
import { rainbowCursor } from "cursor-effects";
let canvas3d ;
onMount(()=>{
  new rainbowCursor({
    length: 3,
    colors: ["red", "blue"],
    size: 4,
  });
})

Index html

Not sure why but there is no reference to the .js files to the scr folder in the index.html file so none of these work when you load the page. So not sure if their was a reason for this or not but thought I would bring it up in case.

Browser extension

Here is an interesting idea :
Put all the code into a browser extension, so we can use the cursors on every websites

Adding to a squarespace site, X and Y coordinates not being picked up correct or offset or something

https://codepen.io/tholman/pen/rxJpdQ
Trying to add this to a friends website for them but having a bit of trouble with alignment

document.body.appendChild(this.element);

Throws all the emojis to the bottom of the page and none show over the content only below, I think this is because of a clear fix.

If Insert it in a div above the clearfix , the x and y coordinates are all slightly off.

Any help would be appreciated

retina canvas sizing

on high density displays, cursors appear pixelated. suggested fix: create a <canvas> element 2x as big as it needs to be and scale it down to 50%

z-index too low

The canvas element has no z-index, so the mouse cursor goes below some elements of the page.

You should apply z-index:2147483647; to it or make it configurable.

Uncaught TypeError: Cannot read properties of null (reading 'appendChild')

<html>
 <link href='https://fonts.googleapis.com/css?family=Mountains of Christmas' rel='stylesheet'>
 <script src="https://unpkg.com/cursor-effects@latest/dist/browser.js"></script>  
 <script> 
   new cursoreffects.snowflakeCursor();
 </script>

There's the top of my web page. I'm getting the following error:

Uncaught TypeError: Cannot read properties of null (reading 'appendChild')
    at new t.snowflakeCursor (browser.js:1:17588)
    at (index):6:3

Please let me know if I'm missing anything

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.