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 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.

Quick-add: + add another resource

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.

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.

            
              <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>
            
          
!
            
              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;
}

            
          
!
            
              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 },
      rx: { start: 18, end: 22 }
    },
    pupil: {
      translateX: { start: -26, end: 26 },
      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)}
            )`
    );
    iris.setAttribute("rx", transform(parabolic, animDatas.iris.rx));

    // Transform pupil
    pupil.setAttribute(
      "transform",
      `translate( 
                ${transform(ease, animDatas.pupil.translateX)}
            )`
    );
    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
  };
})();

startBtn.addEventListener(
  "click",
  () => {
    animePupil.play();
  },
  false
);

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

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

Console