Pen Settings

HTML

CSS

CSS Base

Vendor Prefixing

Add External Stylesheets/Pens

Any URL's added here will be added as <link>s in order, and before the CSS in the editor. If you link to another Pen, it will include the CSS from that Pen. If the preprocessor matches, it will attempt to combine them before processing.

+ add another resource

JavaScript

Babel includes JSX processing.

Add External Scripts/Pens

Any URL's added here will be added as <script>s in order, and run before the JavaScript in the editor. You can use the URL of any other Pen and it will include the JavaScript from that Pen.

+ add another resource

Packages

Add Packages

Search for and use JavaScript packages from npm here. By selecting a package, an import statement will be added to the top of the JavaScript editor for this package.

Behavior

Save Automatically?

If active, Pens will autosave every 30 seconds after being saved once.

Auto-Updating Preview

If enabled, the preview panel updates automatically as you code. If disabled, use the "Run" button to update.

Format on Save

If enabled, your code will be formatted when you actively save your Pen. Note: your code becomes un-folded during formatting.

Editor Settings

Code Indentation

Want to change your Syntax Highlighting theme, Fonts and more?

Visit your global Editor Settings.

HTML

              
                <base href="https://s3-us-west-2.amazonaws.com/s.cdpn.io/4273/">
<label for="orderby">Order by:</label>
<select name="orderby" id="orderby">
  <option value="theme">Theme</option>
  <option value="artist">Artist</option>
  <option value="date">Date</option>
</select>

<div id="rev-works">
<figure itemscope itemtype="http://schema.org/Painting">
  <img src="marat-assassiné.jpg" alt itemprop="image">
  <figcaption itemprop="name">The Death of Marat</figcaption>
    <div>
      <span itemprop="creator">Jacques-Louis David</span>
      <time itemprop="dateCreated" >1793</time>
    </div>
</figure>

<figure itemscope itemtype="http://schema.org/Painting">
    <img src="la-liberté-guidant-le-peuple.jpg" alt itemprop="image">
    <figcaption itemprop="name">Liberty Leading The People</figcaption>
    <div>
      <span itemprop="creator">Eugène Delacroix</span>
      <time itemprop="dateCreated">1830</time>
    </div>
</figure>

<figure itemscope itemtype="http://schema.org/Painting">
  <img src="louis-XVI-roi-de-france-et-de-navarre.jpg" alt itemprop="image">
  <figcaption itemprop="name">Louis XVI, King of France and Navarre</figcaption>
  <div>
    <span itemprop="creator">Antoine-François Callet</span>
    <time itemprop="dateCreated">1789</time>
  </div>
</figure>
</div>
              
            
!

CSS

              
                body { 
  background: #333;
  font-family: Avenir, sans-serif;
}
label { color: #fff; }
#rev-works { 
  display: flex; 
  align-items: flex-start;
  justify-content: space-between;
  width: 90%;
  margin: 0 auto;
}
#rev-works figure { 
  flex: 1;
  background: #fff;
  padding: 10px; 
  opacity: 0;
  transition: .8s opacity; 
}
#rev-works figure.visible { 
  opacity: 1; 
}
#rev-works figure img { 
  width: 100%; height: auto; 
}
#rev-works figcaption { 
  margin: 1rem auto;
  text-align: center;
  font-weight: 700; 
}
#rev-works figure div { 
  display: flex;
  justify-content: space-between;
}
@media screen and (max-width: 1000px) {
  div#rev-works { width: 100%; }
}
@media screen and (max-width: 700px) {
  div#rev-works { 
    flex-direction: column;
    width: 80%;
}
}
@media screen and (max-width: 500px) {
  div#rev-works { 
    width: 100%;
}
}
              
            
!

JS

              
                var theme = document.getElementById("orderby"),
paintings = document.getElementById("rev-works"),
figures = paintings.getElementsByTagName("figure"),
original = paintings.innerHTML;

theme.onchange = function(){ 
var fader = window.setTimeout(fadeOut,0)
var waitforfade = window.setTimeout(replace,1000);
var waitforreplace = window.setTimeout(fadeIn,1600);
  // currently a little crude; should really be a series of more sophisticated callbacks
}

function fadeIn(){
i = 1;
Array.prototype.forEach.call(figures, function(figure) {
setTimeout(function(){ figure.classList.add("visible") }, 400*i)
i++;
})
}

function sortUs(parent, child, key) {
    var items = Array.prototype.slice.call(document.querySelectorAll(parent + " " + child)).sort(function(a, b) {
        var comparA = a.querySelector(key).innerHTML;
        var comparB = b.querySelector(key).innerHTML;
        return (comparA < comparB) ? -1 : (comparA > comparB) ? 1 : 0;
    });
   for (var i = 0; i < figures.length; i++) {
        paintings.appendChild(items[i]);
    }
}

function fadeOut(){      
    i = 1;
Array.prototype.forEach.call(figures, function(figure) {
		setTimeout(function(){ figure.classList.remove("visible"); }, 300*i)
i++;
});
}

function replace() {
   if (theme.value == "theme") { 
	paintings.innerHTML = original;
} else {
	if (theme.value == "artist") { el = "span[itemprop=creator]"; }
	if (theme.value == "date") { el = "time"; }
	sortUs("#rev-works","figure",el);
	}
}

fadeIn();
              
            
!
999px

Console