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. You can use the CSS from another Pen by using it's URL and the proper URL extention.

+ 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

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

              
                <div id="app"></div>

<template id="cube-template">
  <div class="cube">
    <div class="cube__side cube__side--front"></div>
    <div class="cube__side cube__side--back"></div>
    <div class="cube__side cube__side--top"></div>
    <div class="cube__side cube__side--bottom"></div>
    <div class="cube__side cube__side--left"></div>
    <div class="cube__side cube__side--right"></div>
  </div>
</template>

<template id="codepen-logo-template">
  <div class="codepen-logo__wrapper">
    <svg
      class="intro-lines"
      :view-box.camel="'0 0 132 132'"
    >
      <path
        d="M66.25 131.5c36.03 0 65.24-29.22 65.24-65.25M66.22 1C30.2 1 1 30.2 1 66.25"
        :stroke="color"
        fill="none"
      />
    </svg>

    <div class="codepen-logo">
      <!-- top -->
      <cube :color="color" :w="cw" :h="ch" :d="cd" :z="hd * -1 + hh - diff" :ry="90" ></cube>
      <cube :color="color" :w="cw" :h="ch" :d="cd" :x="hd - hh + diff" ></cube>
      <cube :color="color" :w="cw" :h="ch" :d="cd" :z="hd - hh + diff" :ry="90"></cube>
      <cube :color="color" :w="cw" :h="ch" :d="cd" :x="hd * -1 + hh - diff"></cube>

      <cube :color="color" :w="cw" :h="dis" :d="ch" :x="hd - hh + diff" :z="cd * -1 + ch" :ry="-180"></cube>
      <cube :color="color" :w="cw" :h="dis" :d="ch" :x="hd - hh + diff" :ry="180"></cube>
      <cube :color="color" :w="cw" :h="dis" :d="ch" :x="hd * -1 + hh + diff"></cube>
      <cube :color="color" :w="cw" :h="dis" :d="ch" :x="hd * -1 + hh + diff" :z="cd * -1 + ch"></cube>

      <!-- bottom -->
      <cube :color="color" :w="cw" :h="ch" :d="cd" :z="hd * -1 + hh - diff" :ry="90" :y="dis"></cube>
      <cube :color="color" :w="cw" :h="ch" :d="cd" :x="hd - hh + diff" :y="dis"></cube>
      <cube :color="color" :w="cw" :h="ch" :d="cd" :z="hd - hh + diff" :ry="90" :y="dis"></cube>
      <cube :color="color" :w="cw" :h="ch" :d="cd" :x="hd * -1 + hh - diff" :y="dis"></cube>
    </div>
  </div>
</template>

<template id="anim-type">
  <h1 class="anim-type">
    <span class="anim-type__letter" v-for="letter in letterArr">{{ letter }}</span>
  </h1>
</template>

              
            
!

CSS

              
                * {
  margin: 0;
  padding: 0;
  box-sizing: border-box;
}

html, body {
  height: 100vh;
  width: 100vw;
  display: flex;
  align-items: center;
  justify-content: center;
  
  font-family: 'Avenir', Helvetica, Arial, sans-serif;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  color: #2c3e50;
}

.wrapper {
  position: relative;
  -webkit-box-reflect: below 0 linear-gradient(to bottom, transparent, rgba(255,255,255,.4));
  padding-left: 6.5rem;
  padding-bottom: 2rem;
}

// #cube-template
.cube {
  position: absolute;
  top: 0;
  left: 0;
  transform-style: preserve-3d;
  &__side {
    position: absolute;
    width: 100%;
    height: 100%;
  }
}

// #codepen-logo-template
.codepen-logo__wrapper {
  perspective: 2000px;
  transform-style: preserve-3d;
}
.codepen-logo {
  position: absolute;
  left: 0;
  right: 0;
  margin: auto;
  transform-style: preserve-3d;
}
.intro-lines {
  $s: 10rem;
  margin: auto;
  position: absolute;
  width: $s; height: $s;
  top: 3rem; bottom: 0;
  left: (-$s / 2) - 2.8rem; right: 0;
}

// #anim-type
.anim-type {
  font-weight: 300;
  overflow: hidden;
  margin: 0;
  padding-top: 1rem;
}

.anim-type__letter {
  display: inline-block;
}

              
            
!

JS

              
                const Cube = Vue.component('cube', {
  template: '#cube-template',
  props: {
    x:  { default: 0   }, y:  { default: 0   }, z:  { default: 0   },
    w:  { default: 100 }, h:  { default: 100 }, d:  { default: 100 },
    rx: { default: 0   }, ry: { default: 0   }, rz: { default: 0   },
    sx: { default: 1   }, sy: { default: 1   }, sz: { default: 1   },

    color: { default: '#717C89' }
  },
  mounted () {
    const { $el } = this
    const qs = s => $el.querySelector(`.cube__side--${s}`)

    const darker = tinycolor(this.color).darken(8)
    const [bg, to, h, w] = ['background', 'transformOrigin', 'height', 'width']
    const [rx, ry, rz] = ['rotationX', 'rotationY', 'rotationZ']
    const [sx, sy, sz] = ['scaleX', 'scaleY', 'scaleZ']

    TweenMax.set($el.querySelectorAll('.cube__side'), { [bg]: darker.toString() })
    TweenMax.set(qs('back'),   { z: this.d * -1 })
    TweenMax.set(qs('top'),    { [to]: '50% 0', [bg]: this.color, [h]: this.d, [rx]: -90 })
    TweenMax.set(qs('right'),  { [to]: '0 50%', [bg]: this.color, [w]: this.d, [ry]: 90, x: this.w })
    TweenMax.set(qs('bottom'), { [to]: '50% 0', [h]: this.d, [rx]: -90, y: this.h })
    TweenMax.set(qs('left'),   { [to]: '0 50%', [w]: this.d, [ry]: 90 })

    const origin = `center center ${this.d / -2}px`
    TweenMax.set($el, {
      [to]: origin, [h]: this.h, [w]: this.w,
      [sx]: this.sx, [sy]: this.sy, [sz]: this.sz,
      [rx]: this.rx, [ry]: this.ry, [rz]: this.rz,
      x: this.x, y: this.y, z: this.z
    })
  }

})

const CodepenLogo = Vue.component('codepen-logo', {
  template: '#codepen-logo-template',
  components: { Cube },
  props: {
    size: { default: 8 },
    color: { default: '#717C89' },
    onAnimComplete: { type: Function }
  },
  data () {
    const cw = this.size, ch = this.size, cd = 10 * this.size
    const hd = cd / 2, hh = ch / 2
    const diff = 0.001, dis = ch * 5

    return { cw, ch, cd, hd, hh, diff, dis }
  },
  mounted () {
    const el = '.codepen-logo'
    const lines = document.querySelector('.intro-lines')
    const lpath = lines.querySelector('path').getTotalLength()
    const tl = new TimelineMax({
      onComplete: () => this.onAnimComplete && this.onAnimComplete()
    })

    tl
      .set(el, { transformOrigin: `${this.hh}px ${this.dis / 2}px ${this.hd * -1}px` })
      .set(el, { scale: 0, scaleZ: 0, rotationX: -90 })
      .set(lines, { strokeDasharray: lpath, strokeDashoffset: lpath, opacity: 1 })
      .to(el, 1, { scale: 1, scaleZ: 1, ease: Power4.easeOut }, 0.2)
      .to(el, 2, { rotationX: -45, ease: Power4.easeOut }, 0.6)
      .to(el, 0.8, { rotationY: 37, rotationZ: -32, ease: Power4.easeOut }, 0.6)
      .to(lines, 1, { strokeDashoffset: lpath * -1, opacity: 0 }, 0.7)
  }
})

const AnimType = Vue.component('anim-type', {
  template: '#anim-type',
  props: {
    text: { type: String, required: true }
  },
  computed: {
    letterArr () {
      return this.text.split('')
    }
  },
  mounted () {
    const letters = this.$el.querySelectorAll('span')
    TweenMax.staggerFromTo(letters, 1.4, {
      y: '100%',
      opacity: 0
    }, {
      y: '0%',
      opacity: 1,
      delay: 3,
      ease: Elastic.easeOut.config(1, 0.4),
      force3D: true
    }, 0.05)
  }
})

new Vue({
  el: '#app',
  components: { CodepenLogo, AnimType },
  template: `
    <div class="wrapper">
      <codepen-logo :onAnimComplete="listenMouseEvent" />
      <anim-type text="CodePen" class="codepen-title" />
    </div>
  `,
  data () { return { logo: null, px: 0, py: 0, lpx: 0, lpy: 0 } },
  methods: {
    listenMouseEvent () {
      const el = this.$el
      this.logo = document.querySelector('.codepen-logo__wrapper')

      const { top, left } = el.getBoundingClientRect()

      document.addEventListener('mousemove', event => {
        const { clientX: x, clientY: y } = event
        this.px = 2 * (x - left) / window.innerWidth
        this.py = 2 * (y - top) / window.innerHeight
      })

      TweenMax.set(this.logo, { transformOrigin: '50% 50% -40' })
      TweenMax.to(this.logo, 0.8, {
        scale: 0.7,
        x: -80,
        y: 20,
        ease: Expo.easeInOut
      })

      this.rotateLogo()
    },
    rotateLogo () {
      if (this.lpx !== this.px || this.lpy !== this.py) {
        TweenMax.to(this.logo, 1, {
          rotationX: this.py * 10,
          rotationY: this.px * -10
        })
        this.lpx = this.px
        this.lpy = this.py
      }
      requestAnimationFrame(this.rotateLogo)
    }
  }
})

              
            
!
999px

Console