Pen Settings

HTML

CSS

CSS Base

Vendor Prefixing

Add External Stylesheets/Pens

Any URLs added here will be added as <link>s in order, and before the CSS in the editor. You can use the CSS from another Pen by using its URL and the proper URL extension.

+ add another resource

JavaScript

Babel includes JSX processing.

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

Packages

Add Packages

Search for and use JavaScript packages from npm here. By selecting a package, an import statement will be added to the top of the JavaScript editor for this package.

Behavior

Auto Save

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="tape-image">
<svg viewBox="0 0 1000 640">
  <rect id="bump" rx="5" ry="5" width="1000" height="160" x="0" y="400" fill="#111111" />
  <rect id="body" rx="10" ry="10" width="990" height="630" x="5" y="5" fill="#111111" />
  <rect id="window" width="600" height="180" x="200" y="200" rx="10" ry="10" fill="#fff" />
  <circle id="tape-1" cx="290" cy="290" r="265" fill="#555"/>
  <circle id="tape-2" cx="710" cy="290" r="265" fill="#555"/>
  <rect id="window-glass" width="600" height="180" x="200" y="200" rx="10" ry="10" fill="rgba(0,0,0,.2)" />
  <g id="window-frame" fill="#111111">
    <rect width="990" height="195" x="5" y="5" rx="10" ry="10" />
    <rect width="990" height="255" x="5" y="380" rx="10" ry="10" />
    <rect width="200" height="630" x="5" y="5" rx="10" ry="10" />
    <rect width="200" height="630" x="795" y="5" rx="10" ry="10" />
  </g>
  <g id="edge">
    <polygon points="840,640 800,500 200,500 160,640"  fill="#323232" rx="10" ry="10" />
    <circle cx="255" cy="610" r="15" fill="#fff" />
    <circle cx="745" cy="610" r="15" fill="#fff" />
    <circle cx="315" cy="590" r="12" fill="#fff" />
    <circle cx="685" cy="590" r="12" fill="#fff" />
  </g>
  <rect id="label" rx="10" ry="10" width="870" height="100" x="65" y="60" fill="#ffffff" />
  <text id="label-text" x="75" y="126" font-family="Dawning of a New Day, Open Sans, sans-serif" font-size="50">San Fermin - No Devil</text>
  <rect id="reel-cover-1" rx="4" ry="4" width="180" height="180" x="200" y="200" fill="#323232" />
  <rect id="reel-cover-2" rx="4" ry="4" width="180" height="180" x="620" y="200" fill="#323232" />
  <g id="reel-1">
    <circle cx="290" cy="290" r="45" fill="#fff" stroke="#999" stroke-width="5"/>
    <rect x="285" y="245" width="10" height="10" fill="#999"/>
    <rect x="285" y="325" width="10" height="10" fill="#999"/>
    <rect x="285" y="245" width="10" height="10" fill="#999" transform="rotate(60 290,290)"/>
    <rect x="285" y="325" width="10" height="10" fill="#999" transform="rotate(60 290,290)"/>
    <rect x="285" y="245" width="10" height="10" fill="#999" transform="rotate(120 290,290)"/>
    <rect x="285" y="325" width="10" height="10" fill="#999" transform="rotate(120 290,290)"/>
  </g>
  <g id="reel-2">
    <circle cx="710" cy="290" r="45" fill="#fff" stroke="#999" stroke-width="5"/>
    <rect x="705" y="245" width="10" height="10" fill="#999"/>
    <rect x="705" y="325" width="10" height="10" fill="#999"/>
    <rect x="705" y="245" width="10" height="10" fill="#999" transform="rotate(60 710,290)"/>
    <rect x="705" y="325" width="10" height="10" fill="#999" transform="rotate(60 710,290)"/>
    <rect x="705" y="245" width="10" height="10" fill="#999" transform="rotate(120 710,290)"/>
    <rect x="705" y="325" width="10" height="10" fill="#999" transform="rotate(120 710,290)"/>
  </g>
</svg>
</div>
<div id="tape-shadow"></div>
<div id="controls">
  <button id="play">&#9654;</button>
  <button id="rwd"><i>&#9654;</i><i>&#9654;</i></button>
  <button id="fwd"><i>&#9654;</i><i>&#9654;</i></button>
  <button id="eject">Eject</button>
</div>
<form id="searcher">
  <label for="search"><span>Is</span><span>this song</span><span>available on cassette yet?</span></label>
  <input id="search" type="search" value="Lost it to Trying by Son Lux" placeholder="Song by Artist"/>
  <input type="submit" value="Search Soundcloud">
</form>
<div id="counter"></div>
<footer><i></i> | <i></i> | <a></a></footer>
              
            
!

CSS

              
                $back: #f6fbff;//desaturate(#C9DFBD, 0);
$cassette1: #ee5727;
$cassette2: #ee5727;
$cassette3: #ee5727;
$cassette4: #ee5727;
$cassette5: #ee5727;

body,
#window,
#reel-1 circle,
#reel-2 circle,
#edge circle {
  background: $back;
  fill: $back;
}

#label-text {
  fill: #444444;
}

#window-frame,
#body,
#bump {
  fill: desaturate($cassette1, 5);//#246B63;
  
  .alt2 & {
    fill: desaturate($cassette2, 5);//#246B63;
  }
}
#edge polygon,
#reel-cover-1,
#reel-cover-2 {
  fill: darken($cassette1, 15);
    
  .alt2 & {
    fill: darken($cassette2, 15);//#246B63;
  }
}
#reel-1, #tape-1 {
  transform-origin: 290px 290px;
}
#reel-2, #tape-2 {
  transform-origin: 710px 290px;
}
#tape-2 {
  transform: scale(.4);
}


body {
  text-align: center;
  font-family: 'Open Sans', sans-serif
}
* {
  box-sizing: border-box;
}
#tape-image {
  position: relative;
  z-index: 1;
  width: 70vmin;
  margin: 20vmin auto 0;
  //transition: transform .375s cubic-bezier(.25,-0.5,.75,1.5);
  will-change: transform;
  transition: transform .75s cubic-bezier(.57,.01,.17,1.27);
  transform: translateY(-150%);
  
  .active & {
    transform: translateY(0);
  }
}
#tape-shadow {
  position: relative;
  z-index: -1;
  width: 70vmin;
  margin: 2vmin auto 0;
  border-radius: 50%;
  height: 3vmin;
  background: rgba(0, 0, 0, .9);
  filter: blur(10px);
  will-change: transform;
  transition: transform .75s cubic-bezier(.57,.01,.17,1.27), opacity .5s cubic-bezier(.57,.01,.17,1.27);
  transform: scale(0);
  opacity: 0;
  
  .active & {
    transform: scale(1);
    opacity: 1;
  }
}
#controls {
  position: relative;
  z-index: 1;
  width: 70vmin;
  max-width: 25rem;
  margin: 5vmin auto;
  text-align: center;
  overflow: hidden; 
  transform: translate3d(0,-200vmin,0);//scale(0);
  transition: transform .75s cubic-bezier(.57,.01,.17,1.27);
  .active & {
    transform: translate3d(0,0,0);//scale(1);
    opacity: 1;
  }
}
button {
  position: relative;
  display: inline-block;
  float: left;
  appearance: none;
  border: none;
  border-radius: .5rem;
  line-height:2;
  width: 30%;
  font-size: 1rem;
  font-family: 'Open Sans', sans-serif;
  transition: all .2s ease-out;
  margin-bottom: 1rem;
  z-index: 1;
  background: #bbbbbb;
  transform: translate3d(0,0,0);
  
  &:active, &:focus {
    outline: 0;
    box-shadow: none;
  }
  &:focus {
    &::after {
      background-color: #bbb;
    }
  }
  i {
    display: inline-block;
  }
  &#rwd {
    i:nth-of-type(1) {
      transform: translateX(.1rem) scaleX(.8) rotate(180deg);
    }
    i:nth-of-type(2) {
      transform: translateX(-.2rem) scaleX(.8) rotate(180deg);
    }
  }
  &#fwd {
    i:nth-of-type(1) {
      transform: translateX(.1rem) scaleX(.8);
    }
    i:nth-of-type(2) {
      transform: translateX(-.2rem) scaleX(.8);
    }
  }
  &#eject {
    float: none;
  }
  
  &::after {
    position: absolute;
    top: 0;
    bottom: 0;
    right: 0;
    left: 0;
    content: '';
    background: #bbbbbb;
    z-index: -1;
    border-radius: .5rem;
  }
  &::before {
    position: absolute;
    top: .2rem;
    bottom: 0;
    right: 0;
    left: 0;
    content: '';
    background: #555555;
    z-index: -2;
    border-radius: .5rem;
    transform: translate3d(0, .6rem, 0);
    transition: transform .2s ease-out;
  }
  
  &:first-of-type {
    width: 40%;
  }
  
  &.pressed {
    box-shadow: 0 .1rem 0 #323232;
    transform: translate3d(0, .6rem, 0);
    
    &::before {
      transform: translate3d(0, 0rem, 0);
    }
  }
}

#searcher {
  position: absolute;
  top: 10vmin;
  left: 5%;
  z-index: 0;
  width: 90%;
  margin: 1rem auto 0;
  label {
    position: absolute;
    top: 0;
    right: 0;
    bottom: 0;
    left: 0;
    font-size: 1rem;
    z-index: -1;
    
    span {
      display: block;
      margin-bottom: 1.25rem;
    }
  }
  input[type=search] {
    appearance: none;
    border: 2px solid $cassette1;
    border-radius: 0;
    font-size: 1rem;
    padding: .4rem 0;
    margin: 1.7rem auto 0;
    text-align: center;
    width: 100%;
    max-width: 30rem;
    background: #fbfbfe;
    color: #363636;
    font-family: 'Open Sans', sans-serif;
    display: block;
  }
  input[type="submit"] {
    appearance: none;
    background: $cassette1;
    color: $back;
    border: none;
    font-size: 1rem;
    margin-top: 2rem;
    padding: .5rem;
    &:active {
      opacity: .8;
    }
  }
  
  transform: translate3d(0%);//scale(1);
  transition: transform .75s cubic-bezier(.57,.01,.17,1.27);
  
  .active & {
    transform: translate3d(0,-400%,0);//scale(0);
  }
}

#counter {
  opacity: 0;
  
  &.playing {
    animation: faux 500s infinite linear;
  }
  &.paused {
    animation-play-state: paused;
  }
}

@keyframes faux {
  100% {
    opacity: 0;
  }
}

footer {
  position: fixed;
  bottom: 0;
  left: 0;
  right: 0;
  text-align: center;
  font-size: .5rem;
  color: #444;
  opacity: 0;
  z-index: 0;
  padding: .5rem 1rem;
  
  .active & {
    opacity: .8;
  }
}
              
            
!

JS

              
                SC.initialize({
  client_id: 'ae7181a6bf9a2ea203fe24d06a5a5a32'
});

var reel1 = document.querySelector('#reel-1');
var reel2 = document.querySelector('#reel-2');
var tape1 = document.querySelector('#tape-1');
var tape2 = document.querySelector('#tape-2');
var emptyRate = 1.8;
var seekRate = 5;
var seekMs = seekRate * 100;

var reel = {
  keyframes: [{
    transform: 'rotate(0)'
  },{
    transform: 'rotate(-360deg)'
  }],
  options: {
    duration: 3000,
    iterations: Infinity,
    easing: 'linear',
    fill: 'both'
  }
};
var tape = {
  keyframes: [{
    transform: 'scale(1)'
  },{
    transform: 'scale(.4)'
  }],
  options: {
    duration: 30000,
    iterations: 1,
    easing: 'cubic-bezier(.47,.31,.89,1)',
    fill: 'both'
  }
};



document.getElementById('play').addEventListener('click', function(e) {
  var clist = e.currentTarget.classList;
  if (clist.contains('pressed')) {
    if (cassette.isRewinding || cassette.isForwarding) {
      cassette.trackPlayer.pause();
    } else {
      cassette.pause();
    }
    clist.remove('pressed');
  } else if (cassette.tapePlayer1.currentTime >= cassette.track.duration) {
    clist.add('pressed');
    setTimeout(function() {
      clist.remove('pressed');
    }, 200);
  } else {
    if (cassette.isRewinding || cassette.isForwarding) {
      cassette.trackPlayer.play();
    } else {
      cassette.resume();
    }
    clist.add('pressed');
  }
  // SC.resolve('https://soundcloud.com/san-fermin-1/no-devil-1').then(function(song) {
  //   tape.options.duration = song.duration;
  //   SC.stream('/tracks/' + song.id).then(function(player){
  //     player.play();
  //     startPlayerAnimation();
  //   });
  // });
  
  return false;
});

document.getElementById('rwd').addEventListener('click', function(e) {
  var clist = e.currentTarget.classList;
  clist[clist.contains('pressed') ? 'remove' : 'add']('pressed');
  
  if (clist.contains('pressed') && cassette.track) {
    if (cassette.isForwarding) {
      cassette.defastForwardAnimation();
      document.getElementById('fwd').classList.remove('pressed');
    }
    cassette.rewindAnimation();
    cassette.isRewinding = setInterval(function() {
      var time = cassette.trackPlayer.currentTime();
      if (time <= seekMs) {
        cassette.trackPlayer.seek(0);
        cassette.derewindAnimation(true);
        clist.remove('pressed');
      } else {
        cassette.trackPlayer.seek(time - seekMs);
      }
    }, 100);
  } else {
    cassette.derewindAnimation();
  }
});
document.getElementById('fwd').addEventListener('click', function(e) {
  var clist = e.currentTarget.classList;
  clist[clist.contains('pressed') ? 'remove' : 'add']('pressed');
  
  if (clist.contains('pressed') && cassette.track) {
    if (cassette.isRewinding) {
      cassette.derewindAnimation();
      document.getElementById('rwd').classList.remove('pressed');
    }
    cassette.fastForwardAnimation();
    cassette.isForwarding = setInterval(function() {
      var time = cassette.trackPlayer.currentTime();
      if (time >= cassette.track.duration - seekMs) {
        cassette.trackPlayer.seek(cassette.track.duration);
        cassette.defastForwardAnimation(true);
        clist.remove('pressed');
      } else {
        cassette.trackPlayer.seek(time + seekMs);
      }
    }, 100);
  } else {
    cassette.defastForwardAnimation();
  }
});

function search(e) {
  console.log('searching', document.getElementById('search').value);
  document.body.classList.remove('active');
  resetButtons();
  SC.get('/tracks', {
    q: document.getElementById('search').value,
    limit: 1
  }).then(function(tracks) {
    console.log(tracks.length);
    if (tracks.length) {
      cassette.track = tracks[0];
      tape.options.duration = cassette.track.duration;
      cassette.reelInterval = cassette.track.duration / 8;
      var uri = '/tracks/' + cassette.track.id;
      
      var footer = document.querySelector('footer');
      footer.querySelector('i:first-of-type').textContent = cassette.track.title || '';
      footer.querySelector('i:last-of-type').textContent = (cassette.track.user || {}).username || '';
      footer.querySelector('a').textContent = cassette.track.permalink_url;
      footer.querySelector('a').setAttribute('href', cassette.track.permalink_url);
      SC.stream(uri).then(function(player) {
  document.body.classList.add('active');
        cassette.trackPlayer = player;
        
        cassette.labelText = cassette.track.title;
        cassette.start();
      });
    }
  }, function(error, e2) {
    console.log('error ', error, e2);
  });
}

document.getElementById('searcher').addEventListener('submit', function(e) {
  e.preventDefault();
  console.log('in submit');
  search(e);
  console.log('leaving submit');
  return false;
});

//document.body.classList.add('active');

var cassette = {
  playButton: document.getElementById('play'),
  counter: document.getElementById('counter'),
  pause: function() {
    this.reelPlayer1.pause();
    this.reelPlayer2.pause();
    this.tapePlayer1.pause();
    this.tapePlayer2.pause();
    this.trackPlayer.pause();
    this.counter.classList.add('paused');
  },
  start: function() {
    this.startAnimation();
    this.trackPlayer.play();
    this.counter.classList.add('playing');
    this.pause();
  },
  resume: function() {
    this.reelPlayer1.play();
    this.reelPlayer2.play();
    this.tapePlayer1.play();
    this.tapePlayer2.play();
    this.trackPlayer.play();
    this.counter.classList.add('playing'); this.counter.classList.remove('paused');
  },
  track: undefined,
  trackPlayer: undefined,
  startAnimation: function() {
    this.reelPlayer1 = reel1.animate(reel.keyframes, reel.options);
    this.reelPlayer2 = reel2.animate(reel.keyframes, reel.options);

    this.reelPlayer2.playbackRate = emptyRate;

    this.tapePlayer1 = tape1.animate(tape.keyframes, tape.options);
    this.tapePlayer2 = tape2.animate(tape.keyframes, tape.options);

    this.tapePlayer2.reverse();
    this.tapePlayer1.onfinish = function() {
      console.log('tapePlayer1 onfinish');
      cassette.reelPlayer1.pause();
      cassette.reelPlayer2.pause();
      cassette.reelPlayer1.playbackRate = 1;
      cassette.reelPlayer2.playbackRate = emptyRate;
      //cassette.reelPlayer1.pause();
      cassette.counter.classList.add('paused');
      cassette.playButton.classList.remove('pressed');
    }
  },
  set labelText(text) {
    var ele = document.getElementById('label-text')
    ele.textContent = text;
    if (text && text.length > 25) {
      ele.setAttribute('textLength', '830');
      ele.textContent = text.substring(0,23) + '...';
    } else {
      ele.removeAttribute('textLength');
    }
  },
  set reelInterval(interval) {
    console.log('setting interval', interval);
    this.counter.style.animationDuration = Math.floor(interval) + 'ms';
  },
  alterReelRate: function(e) {
    console.log('altering reel rate', this.isForwarding, this.isRewinding);
    if (!this.isForwarding && !this.isRewinding) {
      if (this.reelPlayer2.playbackRate > 1) {
        this.reelPlayer2.playbackRate = this.reelPlayer2.playbackRate - 0.1;
      }
      if (this.reelPlayer1.playbackRate < emptyRate) {
        this.reelPlayer1.playbackRate = this.reelPlayer1.playbackRate + 0.1;
      }
      console.log(this.reelPlayer1.playbackRate, this.reelPlayer2.playbackRate);
    }
  },
  updateReelRate: function() {
    console.log('updating reel rate');
    var percent = this.trackPlayer.currentTime() / this.track.duration;
    var range = emptyRate - 1;
    var rateDiff = percent * range;
    this.reelPlayer1.playbackRate = 1 + rateDiff;
    this.reelPlayer2.playbackRate = emptyRate - rateDiff;
    console.log(this.reelPlayer1.playbackRate, this.reelPlayer2.playbackRate);
  },
  fastForwardAnimation: function() {
    this.tapePlayer1.playbackRate = this.tapePlayer1.playbackRate * seekRate;
    this.tapePlayer2.playbackRate = this.tapePlayer2.playbackRate * seekRate;
    this.reelPlayer1.playbackRate = this.reelPlayer1.playbackRate * seekRate;
    this.reelPlayer2.playbackRate = this.reelPlayer2.playbackRate * seekRate;
    this.keepReelDirection();
  },
  defastForwardAnimation: function(atEnd) {
    clearInterval(this.isForwarding);
    this.isForwarding = false;
    this.tapePlayer1.playbackRate = this.tapePlayer1.playbackRate / seekRate;
    this.tapePlayer2.playbackRate = this.tapePlayer2.playbackRate / seekRate;
    this.reelPlayer1.playbackRate = this.reelPlayer1.playbackRate / seekRate;
    this.reelPlayer2.playbackRate = this.reelPlayer2.playbackRate / seekRate;
    if (!atEnd) {
      this.keepReelDirection(true);
    }
    this.updateReelRate();
  },
  rewindAnimation: function() {
    this.tapePlayer1.playbackRate = this.tapePlayer1.playbackRate * seekRate;
    this.tapePlayer2.playbackRate = this.tapePlayer2.playbackRate * seekRate;
    this.reelPlayer1.playbackRate = this.reelPlayer1.playbackRate * seekRate;
    this.reelPlayer2.playbackRate = this.reelPlayer2.playbackRate * seekRate;
    this.changeReelDirection();
  },
  derewindAnimation: function(atEnd) {
    clearInterval(this.isRewinding);
    this.isRewinding = false;
    this.tapePlayer1.playbackRate = this.tapePlayer1.playbackRate / seekRate;
    this.tapePlayer2.playbackRate = this.tapePlayer2.playbackRate / seekRate;
    this.reelPlayer1.playbackRate = this.reelPlayer1.playbackRate / seekRate;
    this.reelPlayer2.playbackRate = this.reelPlayer2.playbackRate / seekRate;
    this.changeReelDirection(true);
    this.updateReelRate();
  }, 
  changeReelDirection: function(checkPause) {
    this.tapePlayer1.reverse();
    this.tapePlayer2.reverse();
    this.reelPlayer1.reverse();
    this.reelPlayer2.reverse();
    if (checkPause && !this.playButton.classList.contains('pressed')) {
      this.tapePlayer1.pause();
      this.tapePlayer2.pause();
      this.reelPlayer1.pause();
      this.reelPlayer2.pause();
    }
  },
  keepReelDirection: function(checkPause) {
    this.tapePlayer1.play();
    this.tapePlayer2.play();
    this.reelPlayer1.play();
    this.reelPlayer2.play();
    if (checkPause && !this.playButton.classList.contains('pressed')) {
      this.tapePlayer1.pause();
      this.tapePlayer2.pause();
      this.reelPlayer1.pause();
      this.reelPlayer2.pause();
    }
  }
};

function resetButtons() {
  document.getElementById('play').classList.remove('pressed');
  document.getElementById('rwd').classList.remove('pressed');
  document.getElementById('fwd').classList.remove('pressed');
}

document.getElementById('counter').addEventListener('animationiteration', cassette.alterReelRate.bind(cassette));
document.getElementById('counter').addEventListener('webkitAnimationIteration', cassette.alterReelRate.bind(cassette));


document.getElementById('eject').addEventListener('click', function(e) {
  cassette.pause();
  if (cassette.isRewinding) {
    cassette.derewindAnimation();
  }
  if (cassette.isForwarding) {
    cassette.defastForwardAnimation();
  }
  var clist = e.currentTarget.classList;
  clist.add('pressed');
  console.log('ejecting');
  document.body.classList.remove('active');
  setTimeout(function() {
    clist.remove('pressed');
  }, 200);
});
              
            
!
999px

Console