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 Settings

Here you can Sed posuere consectetur est at lobortis. Donec ullamcorper nulla non metus auctor fringilla. Maecenas sed diam eget risus varius blandit sit amet non magna. Donec id elit non mi porta gravida at eget metus. Praesent commodo cursus magna, vel scelerisque nisl consectetur et.

HTML

              
                <button id="startBtn">start</button>
<button id="stopBtn">stop</button>

<svg width="350" heigth="150" viewBox="0 0 350 150">
            <defs>

                <!-- EYE SHAPE -->
                <path
                    id="eyeShape"
                    d="
                        M 27,75
                        S 40 52 75 52
                        120 75 120 75
                        105 93 75 93
                        27 75 27 75 
                        z
                    "   
                />

                <symbol id="eye">
                    <use class="fillEye" xlink:href="#eyeShape"/>
                    
                    <g clip-path="url(#maskeye)">
                        <g id="irisPupil">
                            <ellipse id="iris" class="iris" cx="74" cy="72" rx="18" ry="22"  transform="translate(-23)"/>
                            <ellipse id="pupil" class="pupil" cx="74" cy="72" rx="6" ry="8"  transform="translate(-26)"  />   
                        </g>
                    </g>

                    <use class="strokeEye" xlink:href="#eyeShape"/>
                </symbol>


                <clipPath id="maskeye">
                    <use xlink:href="#eyeShape" />
                </clipPath>
            </defs>


            <use xlink:href="#eye"/>
            <use x="183" xlink:href="#eye" />
        </svg>
              
            
!

CSS

              
                body {
  background-color: #fff;
  margin: 20px;
  margin-top: 10px;
}

/* Eye */
svg {
  margin-top: 20px;
  display: block;
  background-color: #999;
  max-width: 100%;
  height: auto;
}

.fillEye {
  fill: #fff;
  stroke-width: 1px;
  stroke: #666;
}

.strokeEye {
  stroke: #333;
  stroke-width: 6px;
  fill: none;
  stroke-dasharray: 2px 5px;
}

.iris {
  fill: brown;
}

.snowflake {
  fill: #fff;
}

              
            
!

JS

              
                
const startBtn = document.getElementById('startBtn');
const stopBtn = document.getElementById('stopBtn');
// Calcul de la distance
const range = (min, max) => max - min;
// transformations
const transform = (progress, {start, end}) => start + progress * range(start, end);
// timing functions
const tfn = { 
    easeOutCubic : t => Math.pow(t-1, 3) + 1,
    easeInCubic : t => Math.pow(t, 3),
    easeInQuad : t => t*t,
    easeOutQuad : t => t*(2-t),
    parabolic : t => -4*Math.pow(t,2) + 4*t
};

const animePupil = (function(){
    let rafID = null;
    let f = 0;
    let dir = 1;
    let replay;
    
    const NF = 40;
    const pupil = document.getElementById('pupil');
    const iris = document.getElementById('iris');

    const animDatas = { 
        iris : {
            translateX : { start: -23, end: 23 },
            translateY : { start: 0, end: -7 },
            rx : { start: 18, end: 22 }
        },
        pupil : {
            translateX : { start: -26, end: 26 },
            translateY : { start: 0, end: -8 },
            rx : { start: 6, end: 8 }
        }   
    };
        
    const frame = () => {
        f += dir;
        const progress = f/NF;
        const ease = (dir-1) ? tfn.easeInQuad(progress) : tfn.easeOutQuad(progress);
        const parabolic = tfn.parabolic(ease);

        // Transform Iris
        iris.setAttribute(
            'transform', 
            `translate(
                ${transform(ease, animDatas.iris.translateX)}
                ${transform(parabolic, animDatas.iris.translateY)}
            )`
        );
        iris.setAttribute(
            'rx', 
            transform(parabolic, animDatas.iris.rx)
        );

        // Transform pupil
        pupil.setAttribute(
            'transform', 
            `translate( 
                ${transform(ease, animDatas.pupil.translateX)}
                ${transform(parabolic, animDatas.pupil.translateY)}
            )`
        );
        pupil.setAttribute(
            'rx', 
            transform(parabolic, animDatas.pupil.rx)
        );

        if (!(f%NF)) {
            dir *= -1;
            stop();
            replay = setTimeout( () => {
                play(); 
            }, 2500);

            return;
        }

        rafID = requestAnimationFrame(frame); 
    };
    const play = () => {
        if (rafID) return;
        rafID = requestAnimationFrame(frame); 
    };
    const stop = () => {
        clearTimeout(replay);
        cancelAnimationFrame(rafID);
        rafID = null;
    }; 
    return {
        play: play,
        stop: stop
    };
}());

const animeEyelids = (function(){
    let rafID = null;
    let f = 0;
    let replay;
    
    const NF = 20;
    const eyeLids = document.getElementById('eyeShape');
    // Path coordinates
    const animDatas = {
        open :  [40, 52, 75, 52, 120, 75, 120, 75, 105, 93, 75, 93, 27, 75, 27, 75],
        close : [40, 93, 75, 93, 120, 75, 120, 75, 105, 93, 75, 93, 27, 75, 27, 75]
    };

    const frame = () => {
        f += 1;
        const progress = f/NF;
        const parabolic = tfn.parabolic(progress);

        const path = animDatas.open.map((start, index) => {
            const datas = {
                start : start,
                end: animDatas.close[index]
            };
            const point = transform(parabolic, datas);
            return point;
        });

        eyeLids.setAttribute('d', `M 27 75 S ${path.join(' ')} z`);


        if (!(f%NF)) {
            stop();
            replay = setTimeout( () => {
                play(); 
            }, 4000);
            return;
        }

        rafID = requestAnimationFrame(frame); 
    };
    const play = () => {
        if (rafID) return;
        rafID = requestAnimationFrame(frame); 
    };
    const stop = () => {
        f = 0;
        clearTimeout(replay);
        cancelAnimationFrame(rafID);
        rafID = null;
    }; 
    return {
        play: play,
        stop: stop
    };
}());

startBtn.addEventListener('click', () => {
    animePupil.play();
    animeEyelids.play();

}, false);

stopBtn.addEventListener('click', () => {
    animePupil.stop();
    animeEyelids.stop();
}, false);


              
            
!
999px

Console