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.

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

              
                <p id="offscreen-text" class="offscreen-text"></p>
<p id="text" class="text"></p>

<svg id="svg">
</svg>

<input type="text" class="input" id="input" />

<div id="phonics"><b>Pure Phonics:</b>
  <span class="checkbox">
    <input type="checkbox">
    <label data-on="ON" data-off="OFF"></label>
  </span>
</div>

              
            
!

CSS

              
                html, body {
  width: 100%;
  height: 100%;
  overflow: hidden;
  font-family: 'Rubik Mono One', sans-serif;
  background: #22292C;
}

svg {
  width: 100%;
  height: 100%;
  position: absolute;
  top: 0px;
  left: 0px;
  z-index: 0;
}

.input {
  position: absolute;
  z-index: 1;
  bottom: 0px;
  font-size: 20px;
  text-align: center;
  left: 50%;
  transform: translateX(-50%);
  font-family: helvetica, sans-serif;
  bottom: 20px;
  background: none;
  border: 1px solid #ddd;
  color: #eee;
}

.text, .offscreen-text {
  width: 100%;
  top: 50%;
  transform: translateY(-50%);
  display: block;
  position: absolute;
  margin: 0;
}

.offscreen-text {
  text-align: center;
  top: -9999px;
}

.text span {
  position: absolute;
}












#phonics {
  text-align: center;
}
#phonics b {
  display: inline-block;
  color: white;
  height: 55px;
  vertical-align: middle;
}

.checkbox {
  display:inline-block;
  position:relative;
  text-align:left;
  width:60px;
  height:30px;
  background-color:#484850;
  overflow:hidden;
  box-shadow:inset 0 10px 25px rgba(0,0,0, .5), 0px 1px 2px #fff;
  -webkit-border-radius:20px;
  -moz-border-radius:20px;
  border-radius:20px;
  margin:10px;
}

.checkbox input {
  display:block;
  position:absolute;
  top:0;
  right:0;
  bottom:0;
  left:0;
  width:100%;
  height:100%;
  margin:0 0;
  cursor:pointer;
  opacity:0;
  filter:alpha(opacity=0);
  z-index:2;
}

.checkbox label {
  background-color:#151b29;
  background-image:-webkit-linear-gradient(-40deg,rgba(0,0,0,0),rgba(255,255,255,0.1),rgba(0,0,0,0.2));
  background-image:-moz-linear-gradient(-40deg,rgba(0,0,0,0),rgba(255,255,255,0.1),rgba(0,0,0,0.2));
  background-image:-ms-linear-gradient(-40deg,rgba(0,0,0,0),rgba(255,255,255,0.1),rgba(0,0,0,0.2));
  background-image:-o-linear-gradient(-40deg,rgba(0,0,0,0),rgba(255,255,255,0.1),rgba(0,0,0,0.2));
  background-image:linear-gradient(-40deg,rgba(0,0,0,0),rgba(255,255,255,0.1),rgba(0,0,0,0.2));
  -webkit-box-shadow:0 0 0 1px rgba(0,0,0,0.1),0 1px 2px rgba(0,0,0,0.7);
  -moz-box-shadow:0 0 0 1px rgba(0,0,0,0.1),0 1px 2px rgba(0,0,0,0.7);
  box-shadow:0 0 0 1px rgba(0,0,0,0.1),0 1px 2px rgba(0,0,0,0.7);
  -webkit-border-radius:20px;
  -moz-border-radius:20px;
  border-radius:20px;
  display:inline-block;
  width:30px;
  text-align:center;
  font:bold 10px/28px Arial,Sans-Serif;
  color:#999;
  text-shadow:0 -1px 0 rgba(0,0,0,0.7);
  -webkit-transition:margin-left 0.2s ease-in-out;
  -moz-transition:margin-left 0.2s ease-in-out;
  -ms-transition:margin-left 0.2s ease-in-out;
  -o-transition:margin-left 0.2s ease-in-out;
  transition:margin-left 0.2s ease-in-out;
  margin:1px;
}

.checkbox label:before {
  content:attr(data-off);
}

.checkbox input:checked + label {
  margin-left:29px;
  /* green when 'on' 
  background-color: #429f21;
  */
  
  /* blue when 'on' */
  background-color: #0088cc;
  
  color:white;
}

.checkbox input:checked + label:before {
  content:attr(data-on);
}
              
            
!

JS

              
                // Discuss => https://community.keyboard.io/t/hear-yourself-type/792

var pressed = {},
    duration,
    start = 0,
    end = 0,
    key = '',
    purePhonics = false,
    phonicsCheckbox = document.querySelector('#phonics .checkbox');


// Audio sourced from => https://youtu.be/Ch7lGykVwgs

var audio = document.createElement('audio');
audio.src = 'http://res.cloudinary.com/kuzmarski/video/upload/v1511504490/How_to_Pronounce_Sounds_of_the_Alphabet_vecbr1.mp3';

var plink = document.createElement('audio');
plink.src = 'http://res.cloudinary.com/kuzmarski/video/upload/v1511527394/Plink_09_hnwoo9.mp3';

phonicsCheckbox.onclick = function(e) {
  purePhonics = phonicsCheckbox.querySelector('input').checked;
  input.focus();
}

document.onkeydown = function (e) {
  if (pressed[e.which]) return;
  pressed[e.which] = e.timeStamp;
};

document.onkeyup = function (e) {
  if (!pressed[e.which]) return;
  
  key = '';
  if(purePhonics) {
    switch(e.keyCode) {
      case 65:
        key = 'a';
        start = 34.1;
        end = 34.4;
        break;
      case 66:
        key = 'b';
        start = 35.9;
        end = 36;
        break;
      case 67:
        key = 'c';
        start = 38;
        end = 38.4;
        break;
      case 68:
        key = 'd';
        start = 40;
        end = 41;
        break;
      case 69:
        key = 'e';
        start = 42.3;
        end = 42.6;
        break;
      case 70:
        key = 'f';
        start = 44.5;
        end = 45;
        break;
      case 71:
        key = 'g';
        start = 46.8;
        end = 47;
        break;
      case 72:
        key = 'h';
        start = 49.1;
        end = 49.5;
        break;
      case 73:
        key = 'i';
        start = 51.4;
        end = 51.7;
        break;
      case 74:
        key = 'j';
        start = 53.8;
        end = 54;
        break;
      case 75:
        key = 'k';
        start = 56;
        end = 56.2;
        break;
      case 76:
        key = 'l';
        start = 58.6;
        end = 59;
        break;
      case 77:
        key = 'm';
        start = 61;
        end = 61.5;
        break;
      case 78:
        key = 'n';
        start = 63.2;
        end = 64;
        break;
      case 79:
        key = 'o';
        start = 65.8;
        end = 66.2;
        break;
      case 80:
        key = 'p';
        start = 68.1;
        end = 68.3;
        break;
      case 81:
        key = 'q';
        start = 70.6;
        end = 71;
        break;
      case 82:
        key = 'r';
        start = 73.4;
        end = 73.7;
        break;
      case 83:
        key = 's';
        start = 75.5;
        end = 75.8;
        break;
      case 84:
        key = 't';
        start = 77.9;
        end = 78.2;
        break;
      case 85:
        key = 'u';
        start = 80.4;
        end = 81;
        break;
      case 86:
        key = 'v';
        start = 82.8;
        end = 83.4;
        break;
      case 87:
        key = 'w';
        start = 85.3;
        end = 85.6;
        break;
      case 88:
        key = 'x';
        start = 87.6;
        end = 88.2;
        break;
      case 89:
        key = 'y';
        start = 90.4;
        end = 90.7;
        break;
      case 90:
        key = 'z';
        start = 92.8;
        end = 93.4;
        break;
    }
  } else {
    switch(e.keyCode) {
      case 65:
        key = 'a';
        start = 33.2;
        end = 33.5;
        break;
      case 66:
        key = 'b';
        start = 35.1;
        end = 35.4;
        break;
      case 67:
        key = 'c';
        start = 37.1;
        end = 37.4;
        break;
      case 68:
        key = 'd';
        start = 39.2;
        end = 39.6;
        break;
      case 69:
        key = 'e';
        start = 41.5;
        end = 41.8;
        break;
      case 70:
        key = 'f';
        start = 43.7;
        end = 44;
        break;
      case 71:
        key = 'g';
        start = 46;
        end = 46.3;
        break;
      case 72:
        key = 'h';
        start = 48.5;
        end = 48.6;
        break;
      case 73:
        key = 'i';
        start = 50.7;
        end = 50.9;
        break;
      case 74:
        key = 'j';
        start = 53;
        end = 53.2;
        break;
      case 75:
        key = 'k';
        start = 55.3;
        end = 55.6;
        break;
      case 76:
        key = 'l';
        start = 57.8;
        end = 58.07;
        break;
      case 77:
        key = 'm';
        start = 60;
        end = 60.3;
        break;
      case 78:
        key = 'n';
        start = 62.5;
        end = 62.7;
        break;
      case 79:
        key = 'o';
        start = 64.9;
        end = 65.2;
        break;
      case 80:
        key = 'p';
        start = 67.3;
        end = 67.6;
        break;
      case 81:
        key = 'q';
        start = 69.7;
        end = 70;
        break;
      case 82:
        key = 'r';
        start = 72.4;
        end = 72.7;
        break;
      case 83:
        key = 's';
        start = 74.7;
        end = 74.9;
        break;
      case 84:
        key = 't';
        start = 77.1;
        end = 77.3;
        break;
      case 85:
        key = 'u';
        start = 79.5;
        end = 79.7;
        break;
      case 86:
        key = 'v';
        start = 81.9;
        end = 82.3;
        break;
      case 87:
        key = 'w';
        start = 84.3;
        end = 84.6;
        break;
      case 88:
        key = 'x';
        start = 86.9;
        end = 87.3;
        break;
      case 89:
        key = 'y';
        start = 89.4;
        end = 89.6;
        break;
      case 90:
        key = 'z';
        start = 91.9;
        end = 92.3;
        break;
    }
  }
  if (e.keyCode === 32) {
    plink.play();
  }
  console.log(key);
  if (key === '') return;
  
  var audioClone = audio.cloneNode();

  audioClone.addEventListener("timeupdate", function(){
    if(this.currentTime >= this.end) {
      this.pause();
    }
  });
  
  // audioClone.playbackRate = 1.2;
  audioClone.currentTime = start;
  audioClone.end = end;
  audioClone.play();

  duration = (e.timeStamp - pressed[e.which]) / 1000;
  pressed[e.which] = 0;

  return false;
};




























const selectSVG = id => {
  const el = document.getElementById(id);
  return new SVGElement(el);
};

const createSVG = type => {
  const el = document.createElementNS('http://www.w3.org/2000/svg', type);
  return new SVGElement(el);
};

class SVGElement {
  constructor(element) {
    this.element = element;
  }

  set(attributeName, value) {
    this.element.setAttribute(attributeName, value);
  }

  style(property, value) {
    this.element.style[property] = value;
  }
}

const colors = [
  { main: '#FBDB4A', shades: ['#FAE073', '#FCE790', '#FADD65', '#E4C650'] },
  { main: '#F3934A', shades: ['#F7B989', '#F9CDAA', '#DD8644', '#F39C59'] },
  { main: '#EB547D', shades: ['#EE7293', '#F191AB', '#D64D72', '#C04567'] },
  { main: '#9F6AA7', shades: ['#B084B6', '#C19FC7', '#916198', '#82588A'] },
  { main: '#5476B3', shades: ['#6382B9', '#829BC7', '#4D6CA3', '#3E5782'] },
  { main: '#2BB19B', shades: ['#4DBFAD', '#73CDBF', '#27A18D', '#1F8171'] },
  { main: '#70B984', shades: ['#7FBE90', '#98CBA6', '#68A87A', '#5E976E'] }
];
const svg = selectSVG('svg');
const text = document.getElementById('text');
const offscreenText = document.getElementById('offscreen-text');
const input = document.getElementById('input');
let width = window.innerWidth;
let height = window.innerHeight;
let textSize = 0;
let textCenter = 0;
const letters = [];
const prompt = ['t', 'y', 'p', 'e'];
let runPrompt = false;

const resizePage = () => {
  width = window.innerWidth;
  height = window.innerHeight;
  svg.set('height', height);
  svg.set('width', width);
  svg.set('viewBox', `0 0 ${width} ${height}`);
  resizeLetters();
}

const resizeLetters = () => {
  textSize = width / (letters.length+2);
  if (textSize > 100) textSize = 100;
  text.style.fontSize = `${textSize}px`;
  text.style.height = `${textSize}px`;
  text.style.lineHeight = `${textSize}px`;
  offscreenText.style.fontSize = `${textSize}px`;
  const textRect = text.getBoundingClientRect();
  textCenter = textRect.top + textRect.height/2;
  positionLetters();
};

const positionLetters = () => {
  letters.forEach(letter => {
    const timing = letter.shift ? 0.1 : 0;
    TweenLite.to(letter.onScreen, timing, {x:letter.offScreen.offsetLeft+'px', ease: Power3.easeInOut});
    letter.shift = true;
  });
}

const animateLetterIn = letter => {
  const yOffset = (0.5+Math.random()*0.5) * textSize;
  TweenLite.fromTo(letter, 0.4, {scale:0}, {scale:1, ease: Back.easeOut});
  TweenLite.fromTo(letter, 0.4, {opacity:0}, {opacity: 1, ease: Power3.easeOut});
  TweenLite.to(letter, 0.2, {y:-yOffset, ease: Power3.easeInOut});
  TweenLite.to(letter, 0.2, {y:0, ease: Power3.easeInOut, delay: 0.2});
  const rotation = -50 + Math.random()*100;
  TweenLite.to(letter, 0.2, {rotation: rotation, ease: Power3.easeInOut});
  TweenLite.to(letter, 0.2, {rotation: 0, ease: Power3.easeInOut, delay: 0.2});
}

const addDecor = (letter, color) => {
  setTimeout(() => {
    var rect = letter.getBoundingClientRect();
    const x0 = letter.offsetLeft + letter.offsetWidth/2;
    const y0 = textCenter - textSize*0.5;
    const shade = color.shades[Math.floor(Math.random()*4)];
    for (var i = 0; i < 8; i++) addTri(x0, y0, shade);
    for (var i = 0; i < 8; i++) addCirc(x0, y0);
  }, 150);
};

const addTri = (x0, y0, shade) => {
  const tri = createSVG('polygon');
  const a = Math.random();
  const a2 = a + (-0.2 + Math.random()*0.4);
  const r = textSize*0.52;
  const r2 = r + textSize*Math.random()*0.2;
  const x = x0 + r * Math.cos(2 * Math.PI * a);
  const y = y0 + r * Math.sin(2 * Math.PI * a);
  const x2 = x0 + r2 * Math.cos(2 * Math.PI * a2);
  const y2 = y0 + r2 * Math.sin(2 * Math.PI * a2);
  const triSize = textSize * 0.1;
  const scale = 0.3 + Math.random()*0.7;
  const offset = triSize*scale;
  tri.set('points', `0,0 ${triSize*2},0 ${triSize},${triSize*2}`);
  tri.style('fill', shade);
  svg.element.appendChild(tri.element);
  TweenLite.fromTo(tri.element, 0.6, {rotation: Math.random()*360, scale: scale, x: x-offset, y: y-offset, opacity: 1}, {x: x2-offset, y: y2-offset, opacity: 0, ease: Power1.easeInOut, onComplete: () => {
    svg.element.removeChild(tri.element);
  }});
}

const addCirc = (x0, y0) => {
  const circ = createSVG('circle');
  const a = Math.random();
  const r = textSize*0.52;
  const r2 = r + textSize;
  const x = x0 + r * Math.cos(2 * Math.PI * a);
  const y = y0 + r * Math.sin(2 * Math.PI * a);
  const x2 = x0 + r2 * Math.cos(2 * Math.PI * a);
  const y2 = y0 + r2 * Math.sin(2 * Math.PI * a);
  const circSize = textSize * 0.05 * Math.random();
  circ.set('r', circSize);
  circ.style('fill', '#eee');
  svg.element.appendChild(circ.element);
  TweenLite.fromTo(circ.element, 0.6, {x: x-circSize, y: y-circSize, opacity: 1}, {x: x2-circSize, y: y2-circSize, opacity: 0, ease: Power1.easeInOut, onComplete: () => {
    svg.element.removeChild(circ.element);
  }});
}

const addLetter = (char, i) => {
  const letter = document.createElement('span');
  const oLetter = document.createElement('span');
  letter.innerHTML = char;
  oLetter.innerHTML = char;
  text.appendChild(letter);
  const color = colors[i%colors.length];
  letter.style.color = color.main;
  offscreenText.appendChild(oLetter);
  letters[i] = {offScreen: oLetter, onScreen: letter, char: char};
  animateLetterIn(letter);
  addDecor(oLetter, color);
}

const addLetters = value => {
  value.forEach((char, i) => {
    if (letters[i] && letters[i].char !== char) {
      letters[i].onScreen.innerHTML = char;
      letters[i].offScreen.innerHTML = char;
      letters[i].char = char;
    }
    if (letters[i] === undefined) {
      addLetter(char, i);
    }
  });
};

const animateLetterOut = (letter, i) => {
  TweenLite.to(letter.onScreen, 0.1, {scale: 0, opacity: 0, ease: Power2.easeIn, onComplete: () => {
    console.log('removing');
    console.log(letter);
    offscreenText.removeChild(letter.offScreen);
    text.removeChild(letter.onScreen);
    positionLetters();
  }});
  letters.splice(i, 1);
}

const removeLetters = value => {
  for (let i = letters.length-1; i >= 0; i--) {
    const letter = letters[i];
    if (value[i] === undefined) {
      animateLetterOut(letter, i)
    }
  }
}

const onInputChange = () => {
  const value = input.value === '' ? [] : input.value.toLowerCase().split('');
  addLetters(value);
  removeLetters(value);
  resizeLetters();
};

const keyup = (e) => {
  if (runPrompt) {
    input.value = '';
    runPrompt = false;
  };
  onInputChange();
}

const addPrompt = (i) => {
  setTimeout(() => {
    if (runPrompt && prompt[i]) {
      input.value = input.value + prompt[i];
      onInputChange();
      addPrompt(i+1);
    }
  }, 300);
}
  
resizePage();
window.addEventListener('resize', resizePage);
input.addEventListener('keyup', keyup);
input.focus();
addPrompt(0);

              
            
!
999px

Console