Coder Social home page Coder Social logo

caesar's Introduction

Caesar


"THIS IS THE LAST OF MY HAMON! TAKE IT!"

by Caesar Anthonio Zeppeli

Joseph Joestar Cry
License npm downloads GitHub Stars Build Status

Caesar is a developer-friendly library for CSS3 variables get & set.

  • Set CSS variables by caesar.assign method like Object.assign.
  • Get CSS variable value by name using caesar.query.

Demo

Install

$ npm install @realdennis/caesar

or script tag

<script src="https://unpkg.com/@realdennis/[email protected]/dist/index.umd.js"></script>

Usage

Only two methods caesar.assign & caesar.query & caesar.queryOne, the below is usage.

import * as  caesar from '@realdennis/caesar';

const el = document.querySelector('div.container');
caesar.assign(el, {
  duration: '2s',
  delay: '1.5s',
  height: '20px'
});
/* Now the container style would be like below
 ** div.container{
 **   --duration: 2s;
 **   --delay: 1.5s;
 **   --height: 20px;
 **   transition-delay: var(--duration);
 ** }
 **
 */
const { duration, height } = caesar.query(el, ['duration', 'height']);
const { delay } = caesar.queryOne(el,'delay');
console.log(duration); // "2s"
console.log(height); // "20px"
console.log(delay); // "1.5s"

Note

  • When variable does not exist, it'll return empty string (default value is '').
  • Caesar CANNOT get the initial CSS variable value in stylesheet.
  • Each query return would be string type, though you assign in number type. example:
caesar.assign(el, {
  containerTop: 20,
  containerBottom: 10
});
const { containerTop:top } = caesar.query(el, ['containerTop']);
console.log(typeof top); // string
  • If you are using typescript and querySelector, it'll get Element type, please type assertion as HTMLElement.
  • Full document will coming soon...

LICENSE MIT © 2019 realdennis

caesar's People

Contributors

realdennis avatar

Stargazers

 avatar

Watchers

 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.