This repository has been deprecated and will not be maintained.
Injects CSS into the document (it's a perfectly legal procedure)
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/
-
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.
Veinjs has no dependencies, so just include vein.js, wherever it lives on your server:
<script src="vein.js"></script>
Now you can inject CSS.
Here are a few examples:
Let's change all our headers to the color red.
vein.inject('h1', {'color' : 'red'});
Now, let's change both h2 and h3 to greens, and make them bold!
vein.inject(['h2', 'h3'], {'color' : 'green', 'font-weight' : 'bold'});
Alright, maybe not bold...
vein.inject(['h2', 'h3'], {'color' : 'green', 'font-weight' : null});
You know what? Red headers look ugly, let's cancel that.
vein.inject('h1', null);
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'
});
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]