• Stars
    star
    444
  • Rank 98,300 (Top 2 %)
  • Language
    JavaScript
  • License
    MIT License
  • Created over 10 years ago
  • Updated almost 7 years ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

🌈 A JavaScript library for smooth color transitions

sweep.js

A JavaScript library for smoother color transitions. Project page lives here.

About

sweep.js is a small JavaScript library (5kb zipped) that enables proper color transitions through the HSL and HSLuv spaces. Ordinary CSS transitions or existing frameworks convert HSL colors to RGB before transitioning. sweep.js addresses this by letting you transition through the color spectrum.

I've written an in-depth post about the need for HSL transitions here.

Install

bower install -S sweep

...or just download it from here.

Sweep's dependencies are bundled; all you have to do is include the script.

<script src="path/to/sweep.js"></script>

Sweep is wrapped with UMD, so it'll also work as a module in your system of choice.

Usage

Using sweep.js to transition an element's color is easy. Whenever you want to trigger an HSL sweep, call:

sweep(targets, properties, fromColor, toColor[, options])
  • targets - element or array of elements that you wish to animate
  • properties - CSS properties that you wish to animate on those targets (string or array of strings)
  • fromColor - initial color before the transition
  • toColor - final color after the transition
  • options (optional) - an object that can set the following:
    • callback - function to be called once the animation finishes
    • direction - clockwise (1) or counterclockwise (-1)
    • duration - time (in ms) to complete the animation
    • space - 'HSL', 'HSLuv', or 'RGB'

Examples

Trigger a full color cycle on click:

//click

var ex1 = document.querySelector('#ex1');
ex1.addEventListener('click', function() {
  sweep(ex1, 'backgroundColor', '#a8f', '#a8f', {direction: -1, duration: 2000});
}, false);

Animate from purple to green on hover:

//hover

var ex2 = document.querySelector('#ex2');

ex2.addEventListener('mouseenter', function() {
  sweep(ex2, 'backgroundColor', getStyle(ex2, 'background-color'), '#0fa');
}, false);

ex2.addEventListener('mouseleave', function() {
  sweep(ex2, 'backgroundColor', getStyle(ex2, 'background-color'), '#a8f');
}, false);

Licensed under MIT. Created by rileyjshaw.

More Repositories

1

terra

πŸ‘Ύ JS library for simple biological simulations and cellular automata
JavaScript
612
star
2

challenger

πŸ’» Pop-up JavaScript challenges in your browser
JavaScript
102
star
3

po-33

A drum sample loader for my Pocket Operator K.O.
JavaScript
67
star
4

git-cheatsheet

πŸ“‘ Just some simple recipes
47
star
5

tappy

πŸ‘ž A JavaScript library for recording and comparing rhythms
JavaScript
38
star
6

placid-tab

πŸ”Ί A minimal New Tab page for Firefox and Google Chrome.
CSS
16
star
7

dark-theme-everywhere

🌘 Darken bright pages for easier nighttime reading. Unofficial improvement of an unofficial improvement of Inverter.
JavaScript
14
star
8

tinyterm

πŸ“Ÿ The tiniest in-browser terminal you've ever seen.
JavaScript
13
star
9

font-comparison-tool

πŸ”‘ Compare a bunch of local fonts side-by-side
CSS
12
star
10

crypto.christmas

πŸ”’πŸŽ„
JavaScript
12
star
11

nature-of-code

🐻 Scrappy demos that I put together while reading http://natureofcode.com/
JavaScript
10
star
12

plop

πŸ”€ Scriptable text expansion microtool
JavaScript
6
star
13

cnz

πŸͺ’ A really tiny library that generates classname strings.
JavaScript
6
star
14

synthesia

🎨 Synthesizer synesthesia. Turn MIDI notes into colors.
JavaScript
6
star
15

rileyjshaw.github.io

🌸 The personal website of rileyjshaw
JavaScript
6
star
16

.supermac

πŸ’» A collection of dotfiles that I use + some scripts to keep 'em in sync
Shell
6
star
17

2p-snake

🐍 Snake for 2 players on the same keyboard! Saucy.
CoffeeScript
6
star
18

visited-vectors

πŸ”¬ Using the :visited pseudo-class to gain insight into a user's history.
JavaScript
5
star
19

own-this-website

πŸ† An experimental, King of the Hill style game
JavaScript
5
star
20

Seg16

Seg16 is a simple Arduino library for driving 16-segment displays with a HT16K33.
C++
5
star
21

tappy-game

πŸ†˜ Tap the rhythm of the lyrics displayed.
JavaScript
5
star
22

boom

πŸ’£ Declutter webpages and improve readability
JavaScript
5
star
23

window-shopper

🌐 Count and list all page-defined global variables.
JavaScript
4
star
24

rileyjshaw.github.io-v14

🏚️ Yesterday's personal site of rileyjshaw
HTML
4
star
25

mean-tone

πŸ“‰ Takes the average tone of each beat of a wav file
Python
4
star
26

tic-attack-toe

#️⃣ Rapidfire, turnless tic tac toe.
JavaScript
4
star
27

spiral-explorer

πŸŒ€
JavaScript
4
star
28

boxes

πŸ’­ Chat through happenstance.
JavaScript
3
star
29

reduce-background-flicker

πŸ’₯ Prevent that annoying white flash between pages in Chrome
JavaScript
3
star
30

slow-down

🐌 Pitch / speed shifting audio.
Python
3
star
31

important-people

πŸ’ƒ Scraping Wikipedia to figure out who's awesome!
Python
3
star
32

canvas

πŸ–Ό bad code, pretty results, DM @rileyjshaw if it would be helpful for me to clean this up
JavaScript
3
star
33

xoxo-bingo

❌ Friend bingo at XOXO!
JavaScript
3
star
34

domains

πŸ”­ Search for emoji domains and short domains.
Shell
3
star
35

csv-to-gpx

JavaScript
2
star
36

compare-images

Compare two images in a variety of ways.
TypeScript
2
star
37

pocket-calculator

πŸ“₯ Scrapes your unread and archived Pocket content and provides basic stats.
JavaScript
2
star
38

28-hour-day-pebble

πŸ’€ A simple Pebble watchface that runs on 28-hour days and 6-day weeks.
C
2
star
39

Demos

web fiddling
JavaScript
2
star
40

linescapes

πŸŒ„ Generate landscapes from random waveforms
JavaScript
2
star
41

huertbeat

πŸ’— Pulse available Philips hue lights to whatever music is playing.
JavaScript
2
star
42

roll

JavaScript
2
star
43

dim

🦊 A simple dark theme for Firefox
2
star
44

color-screen

Full-screen hex, hsl, and rgb color picker & converter
HTML
2
star
45

write

πŸ“ A chill place to write things
JavaScript
2
star
46

typing-for-two

πŸ‘¬ A typing tutor for two.
HTML
2
star
47

hs-goals

πŸ“† Tracking my goals and progress through Hacker School W'14
JavaScript
1
star
48

touchtone-math-facts

☎️ A math facts app that you can play from a payphone
Ruby
1
star
49

average-color

πŸŽ‰ Returns the average color from a list of HSL arrays
JavaScript
1
star
50

scribbler

✏️ Scribbler loves to combine many types of lines into a single line
JavaScript
1
star
51

blink-sync-player

🎧 Sync your editor's cursor blink with the currently playing song.
CoffeeScript
1
star
52

keyboard-keyboard

🎹 Use a MIDI keyboard as your laptop keyboard!
JavaScript
1
star
53

basic_visualizer

πŸ“Š A simple frequency bar visualizer for audio in Processing.
Processing
1
star
54

mute-color

πŸ”‡ Takes a color that's meant to stand out against your editor's background and makes it shy.
JavaScript
1
star
55

flubber

πŸ’₯ Nobody's perfect! Takes a MIDI file and messes up a few of the notes :)
JavaScript
1
star
56

ace-themes

πŸ‘’ Themes for ajax.org's Ace Editor.
CSS
1
star
57

tiny-tcp

πŸ’¬ Really little node tcp chat server.
JavaScript
1
star
58

wind-alarm

πŸ„ Only wakes you up early if the wind is howling. An alarm for kiteboarders (and windsurfers, I guess....)
Python
1
star
59

nsa

πŸ‡ΊπŸ‡Έ "Key Words & Search Terms" from the Homeland Security Analyst's Desktop Binder (2011)
JavaScript
1
star
60

workflow

πŸ’Ό
JavaScript
1
star
61

glorious-pattern-matcher

πŸ†Ž Inspired by an interview question.
CSS
1
star
62

literate-theme

πŸ“– A CLI tool to update your favorite text editor theme. Emphasizes comments and mutes everything else.
JavaScript
1
star
63

rekt

πŸ‘Ž my biggest project yet (used to live at rekt.website)
1
star
64

tony-montana

πŸ”« Nothing gonna stop you, there's nothing that strong β™«
1
star
65

git-tidy-up

WIP
Python
1
star
66

polyglot

πŸ’± Same program, different languages.
C
1
star
67

tildes

πŸ’Ύ a collection of 1337 microsites
HTML
1
star
68

power-song-finder

πŸƒ Find your running β€œPower Song”
JavaScript
1
star
69

if-on-a-winters-night

1
star
70

mcnxt

πŸ’³ ftw
Java
1
star
71

english-words-directory-trie

Used this for an embedded project where memory was super limited but SD card lookups were cheap. Should juuuust fit on a 32GB FAT32 MicroSD.
1
star
72

filesupply

πŸ• a "webrtc" "file" "sharing" "web" "app"
JavaScript
1
star
73

easy-inbox-zero

πŸ“­ DEPRECATED: Achieve coveted Inbox Zero status without actually doing anything.
JavaScript
1
star
74

phi_fo_fum

A SASS template based on the golden ratio
HTML
1
star
75

tappy-fingerprint

☝️ A simple keystroke dynamics trainer using Tappy
HTML
1
star
76

sanity-kitchen-sink-demo

Sanity.io Kitchen Sink Demo
JavaScript
1
star
77

ribbon

JavaScript
1
star