Coder Social home page Coder Social logo

mpenney99 / veinjs Goto Github PK

View Code? Open in Web Editor NEW

This project forked from etodanik/veinjs

0.0 0.0 0.0 41 KB

Injects CSS into the document (it's a perfectly legal procedure)

Home Page: http://israelidanny.github.io/veinjs/

License: MIT License

JavaScript 60.22% CSS 3.16% HTML 36.63%

veinjs's Introduction

veinjs

Injects CSS into the document (it's a perfectly legal procedure)

What is CSS injection?

CSS injection is the process of injecting CSS definitions into a document dynamically.

If you want to see it in action, see this demo: http://israelidanny.github.io/veinjs/

Why inject?

  • Persistence - Say you want to dynamically make all your sub headers a certain color. You apply CSS properties with jQuery, and everything looks great. But then, you load some more stuff with AJAX, and you notice that your CSS is useless, because it has been only applied to the elements currently living in DOM. That's when injection can save you headache. Just apply any CSS code once, and it's valid - until the next refresh!

  • Performance - Our minions at jsperf.com tell us that injecting CSS rules for a vast number of elements is VERY fast, check it out for yourself: http://jsperf.com/inject-vs-apply/8

  • Media Query Support - You can inject media queries and work responsive magic with veinjs dynamically.

How do I use veinjs?

Step 1 - Include your Javascript

Veinjs has no dependencies, so just include vein.js, wherever it lives on your server:

<script src="vein.js"></script>

Step 2 - Inject!

Now you can inject CSS.

Here are a few examples:

Basic Usage

Let's change all our headers to the color red.

vein.inject('h1', {'color' : 'red'});

Multiple Selectors

Now, let's change both h2 and h3 to greens, and make them bold!

vein.inject(['h2', 'h3'], {'color' : 'green', 'font-weight' : 'bold'});

Canceling a property

Alright, maybe not bold...

vein.inject(['h2', 'h3'], {'color' : 'green', 'font-weight' : null});

Canceling a ruleset by selector

You know what? Red headers look ugly, let's cancel that.

vein.inject('h1', null);

Media Queries

veinjs works with media queries, just like it does with regular selectors.

For instance, let's dynamically apply CSS to make all our secondary headers red on small screens!

vein.inject([{
    '@media (max-width: 768px)': ['h2']
}], {
    'color': '#f00'
});

Component support

var vein = require('veinjs');
vein.inject('h1', {'color' : 'red'});

That's about all there is to know! Happy injecting! If you find any interesting uses for this little library, please let me know!

Issues and Pull Requests are more than welcome!

If you have any questions, drop me a line at: [email protected]

veinjs's People

Contributors

etodanik avatar craga89 avatar retrofox avatar benadamstyles avatar devowhippit avatar joshpangell avatar mjau-mjau avatar mauron85 avatar peterdavehello avatar robertd avatar zspitzer 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.