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

              
                <div id="app"></div>
              
            
!

CSS

              
                *
  box-sizing: border-box

body
  padding: 0
  margin: 0
  background-color: #eee
  user-select: none
  overflow: hidden

#app
  font-size: 0
  text-align: center
  position: absolute
  left: 0
  top: 0
  white-space: pre

.card
  width: 20px
  height: 20px
  background-color: #3498db
  display: inline-block
  position: relative
  transition: .6s
  &.right::before
    content: ''
    width: 30px
    height: 1px
    position: absolute
    top: 50%
    left: 50%
    transform: rotate(45deg) translate(-50%, -50%)
    background-color: #fff
    display: block
    transform-origin: left center
  &.left::before
    content: ''
    width: 30px
    height: 1px
    position: absolute
    top: 50%
    left: 50%
    transform: rotate(45deg) translate(-50%, -50%)
    background-color: #fff
    display: block
    transform-origin: left center
    transform: rotate(-45deg) translate(-50%, -50%)
              
            
!

JS

              
                const app = document.querySelector('#app');
const cellSize = 20;
const cols = Math.ceil(window.innerWidth / cellSize);
const rows = Math.ceil(window.innerHeight / cellSize);

const grid = [];

// Fill the Grid wil Cells
for (let i = 0; i < rows; i++) {
    grid[i] = [];
    const row = document.createElement('div');
    row.classList.add('row');
    for (let j = 0; j < cols; j++) {
        const el = document.createElement('div');
        el.classList.add('card');
        row.appendChild(el);
        grid[i][j] = el;
    }
    app.appendChild(row);
}

// Helper function
const flatten = list =>
    list.reduce((a, b) => a.concat(Array.isArray(b) ? flatten(b) : b), []);

let n = 0;
const flatGrid = flatten([...grid]);
const draw = setInterval(() => {
    const x = Math.random() > 0.5;

    if (x) {
        flatGrid[n].classList.add('right');
        n++;
        if (n >= flatGrid.length) {
            clearInterval(draw);
            StartShuffle();
        }
        return;
    }
    flatGrid[n].classList.add('left');
    n++;

    if (n >= flatGrid.length) {
        clearInterval(draw);
        StartShuffle();
    }
}, 1);

const StartShuffle = function() {
    setInterval(() => {
        const random_el = flatGrid[Math.floor(Math.random() * flatGrid.length)];
        if (random_el.classList.contains('right')) {
            random_el.classList.remove('right');
            random_el.classList.add('left');
            return;
        }
        random_el.classList.remove('left');
        random_el.classList.add('right');
    }, 300);
};

              
            
!
999px

Console