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 is required to process package imports. If you need a different preprocessor remove all packages first.

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

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>
<div class="info">
    <div class="info-title">Robert Penner's easing cheatsheet</div>
    <div class="info-desc">Material for my meetup talk. Concept based on Zeh Fernando's <a href="https://hosted.zeh.com.br/tweener/docs/en-us/misc/transitions.html" target="_blank">Tweener CheatSheet<a/></div>
    <div class="info-links"><a href="https://twitter.com/edankwan" target="_blank">@edankwan</a></div>
</div>
              
            
!

CSS

              
                @import "compass/css3";

html, body {
    position: absolute;
    width: 100%;
    height: 100%;
    min-width: 800px;
    min-height: 545px;
    margin: 0 0;
    font-family: 'Lato', sans-serif;
    background-color: #181818;
}
#app {
    position: relative;
    width: 100%;
    height: 100%;
    overflow: hidden;
}
.block {
  position: absolute;
  left: 0;
  top: 0;
  color: #fff;
  text-align: center;
  line-height: 40px;
  font-size: 14px;
}
.info {
    position: absolute;
    left: 0;
    bottom: 0;
    width: 100%;
    padding: 10px 10px;
    box-sizing: border-box;
    background-color: rgba(0, 0, 0, 0.8);
    color: #fff;
    font-size: 12px;
}
.info-desc {
    color: #ddd;
    font-size: 10px;
}
a {
    color: #ff5f5f;
}
              
            
!

JS

              
                var app = (function(exports, undef){

    var config = {
        autoPlay: true,
        speed: 1,
        moveTime: 0,
        time: 0,
        wait: 0
    };

    var container = document.getElementById('app');

    var canvas = exports.canvas = undef;
    var _ctx;

    var _winWidth;
    var _winHeight;
    var _blockWidth;
    var _blockHeight;
    var _isRendering = false;
    var _af;
    var _blocks = {};
    var _blockList = [];

    var _numOfRows;

    var PADDING_LEFT = 50;
    var PADDING_RIGHT = 50;
    var MARGIN_X = 10;
    var CENTER_MARGIN_X = 30;
    var PADDING_TOP = 50;
    var PADDING_BOTTOM = 50;

    function init() {
        _buildCanvas();
        _buildBlocks();

        var gui = new dat.GUI();
        gui.add(config, 'autoPlay');
        gui.add(config, 'time', 0, 1).listen();
        gui.add(config, 'speed', 0.1, 2).listen();
        gui.add(EaseBlock, 'type', EaseBlock.TYPES);

        container.addEventListener('click', _onClick);
        window.addEventListener('resize', onResize);
        onResize();
        startRender();
    }

    function _buildCanvas() {
        canvas = exports.canvas = document.createElement('canvas');
        _ctx = canvas.getContext('2d');
        container.appendChild(canvas);
    }

    function _buildBlocks() {
        var COLORS = ['#f96e6e', '#f9ee6e', '#6ef4f9'];
        var block, index;
        var i = 0;
        for(var id in easeUtils) {
            index = i ? (i - 1) % 6 : 0;
            block = _blocks[id] = new EaseBlock();
            block.init({
                id: id,
                color: COLORS[index % 3],
                func: easeUtils[id]
            });
            container.appendChild(block.container);
            _blockList.push(block);
            i++;
        }
        _numOfRows = Math.ceil((_blockList.length - 1) / 6) + 1;
    }

    function onResize() {
        _winWidth = canvas.width = container.clientWidth;
        _winHeight = canvas.height = container.clientHeight;

        _blockWidth = EaseBlock.width = (_winWidth - PADDING_LEFT - PADDING_RIGHT - CENTER_MARGIN_X - MARGIN_X * 5) / 6;
        _blockHeight = EaseBlock.height = (_winHeight - PADDING_TOP - PADDING_BOTTOM) / _numOfRows;

        EaseBlock.boxWidth = _blockWidth;
        EaseBlock.boxHeight = _blockHeight - EaseBlock.topHeight - EaseBlock.bottomHeight;
    }

    function startRender() {
        if(!_isRendering) {
            _isRendering = true;
            _animate();
        }
    }

    function stopRender() {
        if(_isRendering) {
            _isRendering = false;
            window.cancelAnimationFrame(_af);
        }
    }

    function _animate() {
        if(_isRendering) {
            _af = window.requestAnimationFrame(_animate);
            render();
        }
    }

    var t = 0;

    function render() {
        _ctx.clearRect(0, 0, _winWidth, _winHeight);
        if(config.moveTime < 1) {
            config.wait = 0;
            config.moveTime += 0.02 * config.speed;
            config.time = config.moveTime;
        } else if(config.autoPlay) {
            config.wait += 0.02;
            if(config.wait > 0.5) {
                config.time = config.moveTime = 0;
            }
        }
        var animation = Math.min(config.time % 1.5, 1);
        var block, containerStyle;
        var x, y, index, row, col;
        for(var i = 0, len = _blockList.length; i < len; ++i) {
            block = _blockList[i];
            index = i - 1;
            col = i ? index % 6 : 0;
            row = i ? ~~(index / 6) + 1 : 0;
            x = ~~(PADDING_LEFT + (col > 2 ? CENTER_MARGIN_X + (MARGIN_X * (col - 1)) : MARGIN_X * col) + _blockWidth * col);
            y = ~~(PADDING_TOP + _blockHeight * row);
            _ctx.save();
            _ctx.translate(x, y);
            block.animation = animation;
            block.render(_ctx);

            containerStyle = block.containerStyle;
            containerStyle.width = _blockWidth + 'px';
            containerStyle.height = _blockHeight + 'px';
            containerStyle.transform = 'translate3d(' + x + 'px,' + y + 'px,0)';

            _ctx.restore();
        }
    }

    function _onClick(evt) {
        config.moveTime = 0;
        config.time = 0;
    }

    exports.init = init;
    exports.onResize = onResize;
    exports.startRender = startRender;
    exports.stopRender = stopRender;
    exports.render = render;

    return exports;

}({}));

app.init();
              
            
!
999px

Console