Examples

Basic gradients animation

Basic gradients animation with 3 gradients in queue composed of 2 colors.

var granimInstance = new Granim({
    element: '#canvas-basic',
    name: 'basic-gradient',
    direction: 'left-right',
    opacity: [1, 1],
    isPausedWhenNotInView: true,
    states : {
        "default-state": {
            gradients: [
                ['#AA076B', '#61045F'],
                ['#02AAB0', '#00CDAC'],
                ['#DA22FF', '#9733EE']
            ]
        }
    }
});
<canvas id="canvas-basic"></canvas>
#canvas-basic {
    position: absolute;
    display: block;
    width: 100%;
    height: 100%;
    top: 0;
    right: 0;
    bottom: 0;
    left: 0;
}

Radial gradients animation

Radial gradients animation with 3 gradients in queue composed of 2 colors.

var granimInstance = new Granim({
    element: '#canvas-radial',
    name: 'radial-gradient',
    direction: 'radial',
    opacity: [1, 1],
    isPausedWhenNotInView: true,
    states : {
        "default-state": {
            gradients: [
                ['#ffb347', '#ffcc33'],
                ['#83a4d4', '#b6fbff'],
                ['#9D50BB', '#6E48AA']
            ]
        }
    }
});
<canvas id="canvas-radial"></canvas>
#canvas-radial {
    position: absolute;
    display: block;
    width: 100%;
    height: 100%;
    top: 0;
    right: 0;
    bottom: 0;
    left: 0;
}

Gradients with an image

Gradients with 3 colors, different opacity and a background image.

var granimInstance = new Granim({
    element: '#canvas-image',
    direction: 'top-bottom',
    opacity: [1, .5, 0],
    isPausedWhenNotInView: true,
    states : {
        "default-state": {
            gradients: [
                ['#485563', '#29323c', '#29323c'],
                ['#00c6ff', '#0072ff', '#0072ff']
            ],
            transitionSpeed: 10000
        }
    }
});
<canvas id="canvas-image"></canvas>
#canvas-image {
    position: absolute;
    display: block;
    width: 100%;
    height: 100%;
    top: 0;
    right: 0;
    bottom: 0;
    left: 0;
    background-image: url("../img/bg-forest.jpg");
    background-position-x: 50%;
}

Gradients with an image mask

Gradients with an image mask to create a gradient animation under a shape.
Look at the logo on the left of the header.

var granimInstance = new Granim({
    element: '#logo-canvas',
    direction: 'left-right',
    opacity: [1, 1],
    states : {
        "default-state": {
            gradients: [
                ['#EB3349', '#F45C43'],
                ['#FF8008', '#FFC837'],
                ['#4CB8C4', '#3CD3AD'],
                ['#24C6DC', '#514A9D'],
                ['#FF512F', '#DD2476'],
                ['#DA22FF', '#9733EE']
            ],
            transitionSpeed: 2000
        }
    }
});
<div class="bloc-logo">
    <canvas id="logo-canvas"></canvas>
    <a href="index.html" class="logo-mask">Granim.js</a>
</div>
.bloc-logo {
    position: relative;
    width: 130px;
    height: 49px;
    float: left;
}

.bloc-logo canvas, .bloc-logo .logo-mask { display: block; width: 130px; height: 49px; }
.bloc-logo .logo-mask { position: absolute; top: 0; left: 0; background-size: 130px; background-image: url("../img/logo-mask.png"); text-indent: -9999px; }

Interactive Gradients

Create a gradients animation that responds to events.
Click on the different states in the gradient animation to see the gradients change.

var granimInstance = new Granim({
    element: '#canvas-interactive',
    name: 'interactive-gradient',
    elToSetClassOn: '.canvas-interactive-wrapper',
    direction: 'diagonal',
    opacity: [1, 1],
    isPausedWhenNotInView: true,
    stateTransitionSpeed: 500,
    states : {
        "default-state": {
            gradients: [
                ['#B3FFAB', '#12FFF7'],
                ['#ADD100', '#7B920A'],
                ['#1A2980', '#26D0CE']
            ],
            transitionSpeed: 10000
        },
        "violet-state": {
            gradients: [
                ['#9D50BB', '#6E48AA'],
                ['#4776E6', '#8E54E9']
            ],
            transitionSpeed: 2000
        },
        "orange-state": {
            gradients: [ ['#FF4E50', '#F9D423'] ],
            loop: false
        }
    }
});

// With jQuery $('#default-state-cta').on('click', function(event) { event.preventDefault(); granimInstance.changeState('default-state'); setClass('#default-state-cta') }); $('#violet-state-cta').on('click', function(event) { event.preventDefault(); granimInstance.changeState('violet-state'); setClass('#violet-state-cta') }); $('#orange-state-cta').on('click', function(event) { event.preventDefault(); granimInstance.changeState('orange-state'); setClass('#orange-state-cta') });
function setClass(element) { $('.canvas-interactive-wrapper a').removeClass('active'); $(element).addClass('active'); };
<div class="canvas-interactive-wrapper">
    <canvas id="canvas-interactive"></canvas>
    <div class="cta-wrapper">
        <a href="#default-state" id="default-state-cta" class="active">Default state</a>
        <a href="#violet-state" id="violet-state-cta">Violet state</a>
        <a href="#orange-state" id="orange-state-cta">Orange state</a>
    </div>
</div>
.canvas-interactive-wrapper {
    position: relative;
    height: 300px;
    text-align: center;
}

.canvas-interactive-wrapper canvas { position: absolute; display: block; width: 100%; height: 100%; top: 0; right: 0; bottom: 0; left: 0; }
.canvas-interactive-wrapper .cta-wrapper { margin-top: 130px; }
.canvas-interactive-wrapper .cta-wrapper a { position: relative; display: inline-block; padding: 3px 7px; border: solid 1px transparent; margin-right: 50px; z-index: 1; text-decoration: none; color: #222; transition: border .3s; }
.canvas-interactive-wrapper .cta-wrapper a.active { border-color: #222; }