Code Monkey home page Code Monkey logo

stylefire's Introduction

Stylefire

Style-setters for CSS, SVG and scroll, optimized for animation.

npm version npm downloads Twitter Follow

  • Tiny: 4kb max, and all stylers can be imported separately.
  • Fast: Optimized for use with animation libraries, Stylefire batches rendering once per frame (this can be selectively overridden).
  • Simple transforms: Replaces the confusing SVG transform model with the simpler CSS model.
  • Line drawing: Full support for SVG path line drawing, simplified to use percentage-based measurements.
  • Cross-browser: Detects and uses vendor CSS prefixes when necessary.
  • Extendable: Easy to create performant stylers for other rendering targets.
  • Type-safe: Written in TypeScript, with Flow definitions available from flow-typed. 'Cause animators love typesafety :)

Install

npm install stylefire --save

Examples

Setting CSS properties

import css from 'stylefire/css';

const div = document.querySelector('div');
const divStyler = css(div);

divStyler.set({
  x: 100,
  y: 100,
  background: '#f00'
});

Demo on CodePen

Line drawing

import { tween } from 'popmotion';
import svg from 'stylefire/svg';

const path = document.querySelector('path');
const pathStyler = svg(path);

tween({ to: 100 })
  .start((v) => path.set('pathLength', v));

Demo on CodePen

Overriding render batching

import css from 'stylefire/css';

const div = document.querySelector('div');
const divStyler = css(div);

divStyler
  .set({ width: 500 })
  .render();

console.log(div.offsetWidth); // 500

divStyler.set({ width: 100 });

console.log(div.offsetWidth); // 500

divStyler.render();

console.log(div.offsetWidth); // 100

Demo on CodePen

Supported by

DriveTribe Open Source

stylefire's People

Contributors

mattgperry avatar

Watchers

James Cloos avatar Martin "Nexii" Pitt 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.