Git Product home page Git Product logo

spatio's Introduction

spatio

Measure space!

Usage

spatio(expression, unit = 'px', context = document.body)
// Measure 1em in pixels
spatio('10pt', 'px');  // 13.328125

// Calcucate at will!
spatio('calc(100vh - 5pt)'); // 957.328125, defaults to pixels

// Pass context element for relative space
var el = document.createElement('div');
el.style.fontSize = '24px';
document.body.appendChild(el);

spatio('1em', 'px', el); // 24

Additional units

// Line height
spatio('1lh');

// Element width and height
spatio('100ew', document.body); // 1920
spatio('100eh', document.body); // 940

// Light seconds
spatio('0.00001ls', 'px') // 335.53125

// Add custom units

// A meter beer is defined as 13 beers, so 1 beer is 100cm / 13
spatio.addUnits({
  beer: spatio('calc(100cm / 13)')
});

spatio('1beer', 'cm') // 7.694789081885856

spatio's People

Contributors

joostverdoorn avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar

Watchers

 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.