Simple Stylar Demo

This is a simple demo of what can be done with the Stylar library.

by DamonOehlman

HTML

<script src="https://github.com/DamonOehlman/stylar/raw/master/stylar.js"></script>
<section id="boxes">
    <div class="box"></div>
    <div class="box"></div>
    <div class="box"></div>
    <div class="box"></div>
    <div class="box"></div>
</section>

<section class="about">
    <h2>Stylar Demo</h2>
    <p>
        Stylar is a simple javascript library designed to make
        retrieving and updating the CSS for an element (or array of elements).
    </p>
</section>

<a target="_blank" href="https://github.com/DamonOehlman/stylar"><img style="position: absolute; top: 0; right: 0; border: 0;" src="https://a248.e.akamai.net/assets.github.com/img/7afbc8b248c68eb468279e8c17986ad46549fb71/687474703a2f2f73332e616d617a6f6e6177732e636f6d2f6769746875622f726962626f6e732f666f726b6d655f72696768745f6461726b626c75655f3132313632312e706e67" alt="Fork me on GitHub"></a>

CSS

.box {
    background: red;
    height: 50px;
    width: 50px;
    margin: 10px;
    
    -webkit-transition: all ease-in-out 0.5s;
    -moz-transition: all ease-in-out 0.5s;
    -o-transition: all ease-in-out 0.5s;
    -ms-transition: all ease-in-out 0.5s;
    transition: all ease-in-out 0.5s;
}

body {
    font-family: Helvetica;
    margin-top: 20px;
}

section.about {
    margin: 10px 0;
    background: #333;
    color: white;
    padding: 10px;
    position: fixed;
    bottom: 0px;
    width: 100%;
}

h2 {
    font-size: 1.1em;
    font-weight: bold;
margin-bottom: 5px;        
}

#boxes {
    margin: 10px;
}

JavaScript

// stylar uses the querySelector api under the hood if you 
// pass it a string, but you can pass it dom elements directly too
stylar('.box:nth-child(2n)')
    
    // set the background color, which will transition 
    .set('background', 'navy')
    
    // stylar strips vendor prefixes before attempting to detect
    // the "correct" prefix
    .set('-moz-transform', 'translate(50px, 0px)')
    
    // make the boxes rounded
    // the vendor prefix will be added
    .set('border-radius', '10px');