Giter VIP home page Giter VIP logo

sweep's Introduction

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 HUSL 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(target, properties, fromColor, toColor[, options])
  • target - element that you wish to animate
  • properties - CSS properties that you wish to animate (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', 'HUSL', 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);

Licenced under MIT. Created by rileyjshaw.

sweep's People

Contributors

rileyjshaw avatar

Watchers

 avatar  avatar  avatar

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.