cssAudio - Activefile-genericCSS - ActiveGeneric - ActiveHTML - ActiveImage - ActiveJS - ActiveSVG - ActiveText - Activefile-genericVideo - ActiveLovehtmlicon-new-collectionicon-personicon-teamlog-outoctocatpop-outspinnerstartv

Pen Settings

CSS Base

Vendor Prefixing

Add External CSS

These stylesheets will be added in this order and before the code you write in the CSS editor. You can also add another Pen here, and it will pull the CSS from it. Try typing "font" or "ribbon" below.

Quick-add: + add another resource

Add External JavaScript

These scripts will run in this order and before the code in the JavaScript editor. You can also link to another Pen here, and it will run the JavaScript from it. Also try typing the name of any popular library.

Quick-add: + add another resource

Code Indentation

     

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.

            
              <script src="//frzr.js.org/frzr.min.js"></script>

<script>
var setChildren = frzr.setChildren;
var List = frzr.List;
  
function animatedList (View, key, initData) {
  var list = new List(View, key, initData, true);
  var originalUpdate = list.update;

  list.update = function update (data) {
    var parent = list.parent;
  
    onbefore && onbefore(list.views);

    originalUpdate.call(list, data, function (added, updated, removed) {
      parent && setChildren(parent, list.views.concat(removed));
      onafter && onafter(added, updated, removed);
    });
  }
  return list;

  function onbefore (views) {
    var parent = list.parent;

	    // before update, get every views' position:
    views.forEach(function (view) {
      view.startPos = view.el.getBoundingClientRect();
    });
  }

  function onafter (added, updated, removed) {
    var parent = list.parent;

	    // fade in new views:
    added.forEach(function (view) {
      view.el.style.opacity = 0;
      setTimeout(function () {
        view.el.style.transition = 'opacity 1s';
        view.el.style.opacity = 1;
      }, 0);
    });

    	// move updated / removed back to the old position
    updated.concat(removed).forEach(function (view) {
      var endPos = view.el.getBoundingClientRect();
      var diffPos = [
        view.startPos.left - endPos.left,
        view.startPos.top - endPos.top
      ];
      view.el.style.transition = '';
      view.el.style.transform = 'translate(' + diffPos.join('px,') + 'px)';
    });

	    // animate updated views back to new place
    updated.forEach(function (view) {
      setTimeout(function () {
        view.el.style.transition = 'transform 1s';
        view.el.style.transform = '';
      }, 0);
    });

    	// fade out removed views
    removed.forEach(function (view) {
      setTimeout(function () {
        view.el.style.transition = 'opacity 1s';
        view.el.style.opacity = 0;
      }, 0);
    });
  }
}
</script>
            
          
!
            
              * {
  margin: 0;
  padding: 0;
  box-sizing: border-box;
}
body {
  background-color: #eee;
  padding: 1.5rem;
  font-family: sans-serif;
  font-size: .75rem;
}
.item {
  display: inline-block;
  vertical-align: middle;
  margin: .5rem;
  padding: .25rem;
  background-color: #fff;
  box-shadow: 0 1px 2px rgba(0, 0, 0, .25);
}
.item p {
  padding: .25rem;
  text-align: center;
}
            
          
!
            
              
var ITEMS = 50;
var ITEMS_MIN = 25;
var ITEMS_MAX = 50;
var el = frzr.el;
var mount = frzr.mount;
var unmount = frzr.unmount;
var List = frzr.List
var img = [];
var data = [];
var i = 0;

for (var i = 0; i < ITEMS; i++) {
  var width = Math.random() * 100 + 75 | 0;
  var height = Math.random() * 100 + 75 | 0;
  
  img[i] = {
    width: width,
    height: height,
    src: 'https://unsplash.it/' + width + '/' + height + '/'
  };
}

function Item (initData, data) {
  this.el = el('div', { class: 'item' },
    this.img = el('img', { width: data.img.width, height: data.img.height, src: data.img.src }),
    this.title = el('p', data.name)
  );
}

Item.prototype.update = function (data) {
  this.data = data;
}

var list = animatedList(Item, 'id');

updateData();

setInterval(function () {
  updateData();
}, 2000);

mount(document.body, list);

function updateData () {
  for (var i = 0; i < ITEMS; i++) {
    
    data[i] = {
      id: i,
      name: 'Image ' + (i + 1),
      img: img[i]
    }
  }
  data.sort(function () {
    return Math.random() - .5;
  });
  data.length = (Math.random() * (ITEMS_MAX - ITEMS_MIN) | 0) + ITEMS_MIN;
  list.update(data);
} 

            
          
!
999px
Loading ..................

Console