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

              
                .container
  - for (let l = 0; l < 3; l++)
    .layer__wrapper
      .layer
        - for(let c = 0; c < 3; c++)
          .column
            - for(let c = 0; c < 3; c++)
              .cube
              
            
!

CSS

              
                *
  box-sizing border-box

body
  align-items      center
  background-color #111
  color            #fafafa
  display          flex
  height           100vh
  justify-content  center
  overflow          hidden
  width            100vw

$movement  = 100%
$size      = 5vh
$primary   = #d91e18
$secondary = #19b5fe
$tertiary  = #f39c12

.container
  position relative
  transform rotateX(45deg) translateY(-($size * 3))
  @media(min-width 768px)
    $size = 10vh
    transform rotateX(45deg) translateY(-($size * 3))

.layer
  display flex
  transform rotateX(45deg) rotate(45deg)

  &__wrapper
    position absolute
    for $child in (1..3)
      &:nth-child({$child})
        transform translate(-50%, (-($size) + (($child - 1) * $size)))
        z-index 3 - ($child - 1)
        @media(min-width: 768px)
          $size = 10vh
          transform translate(-50%, (-($size) + (($child - 1) * $size)))

.cube
  background-color $primary
  height $size
  position relative
  width  $size
  @media(min-width: 768px)
    $size = 10vh
    height $size
    width $size

  &:before
  &:after
    content ''
    display block
    height 100%
    position absolute
    width  100%

  &:before
    background-color $secondary
    left 100%
    top 50%
    max-width 100px
    transform skewY(45deg) scale(1.02)

  &:after
    background-color $tertiary
    left 50%
    top 100%
    transform skewX(45deg) scale(1.02)
              
            
!

JS

              
                const CLASSES = {
  COLUMN: 'column',
  CUBE: 'cube',
  LAYER: 'layer__wrapper',
}

const cubeSize = parseFloat(getComputedStyle(document.querySelector(`.${CLASSES.CUBE}`)).height, 10)
const duration = .5
const delay = 0.15


/**
 * Handle column animations
 *
 * 1. Grab the first and last column of each layer
 * 2. Create a timeline where the columns move out
 * 3. Create a reversed version of that timeline in a tween where
 *  columns move back to original position
 */
const firstColumns = document.querySelectorAll(`.${CLASSES.COLUMN}:first-child`)
const lastColumns = document.querySelectorAll(`.${CLASSES.COLUMN}:last-child`)

const columnTl = new TimelineLite()

const moveFirstColumns = TweenLite.to(firstColumns, duration, {
  x: '-100%',
  delay,
})

const moveLastColumns = TweenLite.to(lastColumns, duration, {
  x: '100%',
  delay,
})

// Create parallel animation using position parameter
columnTl.add(moveFirstColumns)
columnTl.add(moveLastColumns, 0)

const columnTlR = TweenLite.to([firstColumns, lastColumns], duration, {
  x: '0%',
  delay,
})

/**
 * Handle cube animations
 *
 * 1. Grab the first and last cube of each column
 * 2. Create a timeline that moves those cubes out
 * 3. Create a reversed version of that timeline in a tween
 */
const firstCubes = document.querySelectorAll(`.${CLASSES.CUBE}:first-child`)
const lastCubes = document.querySelectorAll(`.${CLASSES.CUBE}:last-child`)

const cubeTl = new TimelineLite()

const moveFirstCubes = TweenLite.to(firstCubes, duration, {
  y: '-100%',
  delay,
})

const moveLastCubes = TweenLite.to(lastCubes, duration, {
  y: '100%',
  delay,
})

// Create parallel animation using position parameter
cubeTl.add(moveFirstCubes)
cubeTl.add(moveLastCubes, 0)

const cubeTlR = TweenLite.to([firstCubes, lastCubes], duration, {
  y: '0%',
  delay,
})

/**
 * Handle the layer animations
 *
 * 1. Grab the first and last layer
 * 2. Create a timeline that moves the layers up and down
 * 3. Create a timeline that reverses that initial timeline, could .reverse() be used here?
 */
const firstLayer = document.querySelectorAll(`.${CLASSES.LAYER}:first-child`)
const lastLayer = document.querySelectorAll(`.${CLASSES.LAYER}:last-child`)

const layerTl = new TimelineLite()

const moveFirstLayer = TweenLite.to(firstLayer, duration, {
  x: '-50%',
  y: `-${2 * cubeSize}px`,
  delay,
})

const moveLastLayer = TweenLite.to(lastLayer, duration, {
  x: '-50%',
  y: `${2 * cubeSize}px`,
  delay,
})

layerTl.add(moveFirstLayer)
layerTl.add(moveLastLayer, 0)

const layerTlR = new TimelineLite()

layerTlR.add(TweenLite.to(firstLayer, duration, {
  x: '-50%',
  y: `-${cubeSize}px`,
  delay,
}))

layerTlR.add(TweenLite.to(lastLayer, duration, {
  x: '-50%',
  y: `${cubeSize}px`,
  delay,
}), 0)

/**
 * Create the main repeating timeline
 */
const timeline = new TimelineMax()
timeline.add(columnTl)
  .add(cubeTl)
  .add(layerTl)
  .add(columnTlR)
  .add(cubeTlR)
  .add(layerTlR)
  .repeat(-1)
              
            
!
999px

Console