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

              
                -
  const ITEMS = [
    {
      id: 'a',
      src: "https://source.unsplash.com/ezSFnAFi9hY/500x500",
      alt: "cut citrus fruits.",
      txt: "Lorem Ipsum",
    },
    {
      id: 'b',
      src: "https://source.unsplash.com/TIGDsyy0TK4/500x500",
      alt: "sliced mango.",
      txt: "Dolor Sit",
    },
    {
      id: 'c',
      src: "https://source.unsplash.com/TdDtTu2rv4s/500x500",
      alt: "a bunch of blueberries.",
      txt: "Amet Consectetur",
    },
    {
      id: 'd',
      src: "https://source.unsplash.com/eudGUrDdBB0/500x500",
      alt: "a pineapple sitting on a table.",
      txt: "Adipiscing Elit",
    },
    {
      id: 'e',
      src: "https://source.unsplash.com/eJH4f1rlG7g/500x500",
      alt: "frozen raspberries.",
      txt: " Nunc Tortor",
    },
    {
      id: 'f',
      src: "https://source.unsplash.com/24RUrLSW1HI/500x500",
      alt: "a sliced strawberry.",
      txt: "Metus Mollis",
    },
    {
      id: 'g',
      src: "https://source.unsplash.com/h5yMpgOI5nI/500x500",
      alt: "an arrangement of assorted sliced fruits.",
      txt: "Congue Sagittis",
    },
    {
      id: 'h',
      src: "https://source.unsplash.com/2TYrR2IB72s/500x500",
      alt: "sliced watermelons.",
      txt: "Vestibulum Et",
    },
    {
      id: 'i',
      src: "https://source.unsplash.com/1cWZgnBhZRs/500x500",
      alt: "grapefruits, lemons, and pomegranates.",
      txt: "Donec Eget",
    },
    {
      id: 'j',
      src: "https://source.unsplash.com/9aOswReDKPo/500x500",
      alt: "half of an avocado.",
      txt: "Maecenas et Justo",
    },
    {
      id: 'k',
      src: "https://source.unsplash.com/Nl7eLS8E2Ss/500x500",
      alt: "half of a lime.",
      txt: "Malesuada Quam",
    },
    {
      id: 'l',
      src: "https://source.unsplash.com/3HhXWJzG5Ko/500x500",
      alt: "a single cherry with stem.",
      txt: "Ultricies Sollicitudin",
    },
    {
      id: 'm',
      src: "https://source.unsplash.com/fczCr7MdE7U/500x500",
      alt: "a bunch of bananas.",
      txt: "Gravida Nibh",
    },
    {
      id: 'n',
      src: "https://source.unsplash.com/uI900SItAyY/500x500",
      alt: "three pears.",
      txt: "Pellentesque Sapien",
    },
    {
      id: 'o',
      src: "https://source.unsplash.com/0AynZdszfz0/500x500",
      alt: "a basket full of peaches next to a plate with sliced peaches.",
      txt: "Suspendisse Vel",
    },
    {
      id: 'p',
      src: "https://source.unsplash.com/C6JhUKs9q8M/500x500",
      alt: "a bowl of avocados.",
      txt: "Mauris Consectetur",
    },
  ]

mixin grids()
  .grid.grid--right(class!=attributes.class)
    .grid__item.top-left
    .grid__item.right-long
    .grid__item.bottom-left
  .grid.grid--left(class!=attributes.class)
    .grid__item.left-long
    .grid__item.top-right
    .grid__item.bottom-right
.scene
  .grid__container
    +grids()(class="on-screen")
    +grids()(class="off-screen off-screen--top")
    +grids()(class="off-screen off-screen--right")
    +grids()(class="off-screen off-screen--bottom")
    +grids()(class="off-screen off-screen--left")
    +grids()(class="off-screen off-screen--top-right")

  ul
    for item in ITEMS
      li(class=item.id)
        if (item.id === 'a')
          h1 Parks and Fruits
        img(src=item.src alt=item.alt)
        span= item.txt

svg.scroll-icon(viewBox="0 0 24 24")
  path(fill="currentColor" d="M20 6H23L19 2L15 6H18V18H15L19 22L23 18H20V6M9 3.09C11.83 3.57 14 6.04 14 9H9V3.09M14 11V15C14 18.3 11.3 21 8 21S2 18.3 2 15V11H14M7 9H2C2 6.04 4.17 3.57 7 3.09V9Z")
              
            
!

CSS

              
                *
*:after
*:before
  box-sizing border-box

body
  min-height 100vh
  overflow hidden
  background hsl(0, 0%, 10%)

.grid

  display grid
  width 100%
  height 100%
  background hsl(0, 0%, 10%)
  grid-template-columns repeat(2, 1fr)
  grid-template-rows repeat(2, 1fr)
  grid-gap 2vmin
  position absolute
  top 0
  left 0

  &__container
    height 100vh
    width 100vw
    position fixed
    top 50%
    left 50%
    transform translate(-50%, -50%)

  // &__item
  //   background hsl(280, 80%, 80%)

.grid--right .grid__item:nth-of-type(2)
.grid--left .grid__item:nth-of-type(1)
  grid-row span 2

.off-screen
  &--top
    transform translate(0, calc(-100% - 2vmin))
  &--right
    transform translate(calc(100% + 2vmin), 0)
  &--bottom
    transform translate(0, calc(100% + 2vmin))
  &--left
    transform translate(calc(-100% - 2vmin))
  &--top-right
    transform translate(calc(100% + 2vmin), calc(-100% - 2vmin))

li
ul
  list-style-type none

li
  overflow hidden
  position absolute

.scene
  position fixed
  height 100vh
  width 100vw

ul
  padding 0
  margin 0
  height 100vh
  width 100vw
  position fixed

h1
  font-size 3rem
  position absolute
  top 50%
  left 50%
  transform translate(-50%, -50%)
  z-index 3
  background white
  padding 1rem
  border-radius 0.5rem
  font-family sans-serif

img
  height 100%
  width 100%
  position absolute
  object-fit cover
  filter saturate(0.75)

span
  font-weight bold
  background white
  position absolute
  display inline-block
  right 2rem
  bottom 2rem
  font-size 2rem
  padding 1rem
  border-radius 0.5rem
  font-family sans-serif

.scroll-icon
  height 48px
  position fixed
  top 1rem
  right 1rem
  z-index 10
  color white
  animation action 4s infinite
  background black
  padding 0.5rem
  border-radius 50%

@keyframes action
  0%, 25%, 50%, 100%
    transform translate(0, 0)
  12.5%, 37.5%
    transform translate(0, 25%)
              
            
!

JS

              
                import debounce from 'https://cdn.skypack.dev/lodash/debounce'
const { gsap, Flip, ScrollTrigger } = window

console.info(debounce)

gsap.registerPlugin(Flip)
gsap.registerPlugin(ScrollTrigger)

gsap.set(window, {
  pageYOffset: 0,
})

// Use Flip to set initial positions on the grids.
const setFlips = () => {
  Flip.fit('.a', '.on-screen')
  Flip.fit('.b', '.off-screen--left .top-left')
  Flip.fit('.c', '.off-screen--left .bottom-left')
  Flip.fit('.d', '.off-screen--left .right-long')
  Flip.fit('.e', '.off-screen--left .right-long')
  Flip.fit('.f', '.off-screen--top')
  Flip.fit('.g', '.off-screen--right .left-long')
  Flip.fit('.h', '.off-screen--top')
  Flip.fit('.i', '.off-screen--left .right-long')
  Flip.fit('.j', '.off-screen--bottom')
  Flip.fit('.k', '.off-screen--left .right-long')
  Flip.fit('.l', '.off-screen--bottom .left-long')
  Flip.fit('.m', '.off-screen--bottom')
  Flip.fit('.n', '.off-screen--right .left-long')
  Flip.fit('.o', '.off-screen--top')
  Flip.fit('.p', '.off-screen--left .right-long')
}

const FLIP_OPTS = {
  duration: 0.5,
  ease: 'none',
}

const genFlips = () =>
  gsap
    .timeline({
      // repeat: -1,
      paused: true,
    })
    // First transition
    .add(
      gsap
        .timeline({
          delay: 1,
        })
        .add(Flip.fit('.a', '.off-screen--right', FLIP_OPTS))
        .add(Flip.fit('.b', '.on-screen .top-left', FLIP_OPTS), '<')
        .add(Flip.fit('.c', '.on-screen .bottom-left', FLIP_OPTS), '<')
        .add(Flip.fit('.d', '.on-screen .right-long', FLIP_OPTS), '<')
    )
    // Second Transition
    .add(
      gsap
        .timeline({
          delay: 1,
        })
        .add(Flip.fit('.b', '.on-screen', FLIP_OPTS))
        .add(Flip.fit('.c', '.off-screen--bottom', FLIP_OPTS), '<')
        .add(Flip.fit('.d', '.off-screen--right .left-long', FLIP_OPTS), '<')
    )
    // Third Transition - Getting .e and .f involved
    .add(
      gsap
        .timeline({
          delay: 1,
        })
        .add(Flip.fit('.b', '.on-screen .bottom-right', FLIP_OPTS))
        .add(Flip.fit('.e', '.on-screen .left-long', FLIP_OPTS), '<')
        .add(Flip.fit('.f', '.on-screen .top-right', FLIP_OPTS), '<')
    )
    // Fourth Transition - Reverse of Third
    .add(
      gsap
        .timeline({
          delay: 1,
        })
        .add(Flip.fit('.b', '.on-screen', FLIP_OPTS))
        .add(Flip.fit('.e', '.off-screen--left .right-long', FLIP_OPTS), '<')
        .add(Flip.fit('.f', '.off-screen--top', FLIP_OPTS), '<')
    )
    // Fifth Transition
    .add(
      gsap
        .timeline({
          delay: 1,
        })
        .add(Flip.fit('.b', '.on-screen .bottom-left', FLIP_OPTS))
        .add(Flip.fit('.g', '.on-screen .right-long', FLIP_OPTS), '<')
        .add(Flip.fit('.h', '.on-screen .top-left', FLIP_OPTS), '<')
    )
    // Sixth Transition - Reverse of Fifth
    .add(
      gsap
        .timeline({
          delay: 1,
        })
        .add(Flip.fit('.b', '.on-screen', FLIP_OPTS))
        .add(Flip.fit('.g', '.off-screen--right .left-long', FLIP_OPTS), '<')
        .add(Flip.fit('.h', '.off-screen--top', FLIP_OPTS), '<')
    )
    // Seventh Transition
    .add(
      gsap
        .timeline({
          delay: 1,
        })
        .add(Flip.fit('.b', '.on-screen .top-right', FLIP_OPTS))
        .add(Flip.fit('.i', '.on-screen .left-long', FLIP_OPTS), '<')
        .add(Flip.fit('.j', '.on-screen .bottom-right', FLIP_OPTS), '<')
    )
    // Eighth Transition
    .add(
      gsap
        .timeline({
          delay: 1,
        })
        .add(Flip.fit('.b', '.off-screen--top-right .bottom-left', FLIP_OPTS))
        .add(Flip.fit('.i', '.on-screen .top-right', FLIP_OPTS), '<')
        .add(Flip.fit('.j', '.off-screen--right', FLIP_OPTS), '<')
        .add(Flip.fit('.k', '.on-screen .left-long', FLIP_OPTS), '<')
        .add(Flip.fit('.l', '.on-screen .bottom-right', FLIP_OPTS), '<')
    )
    // Ninth Transition
    .add(
      gsap
        .timeline({
          delay: 1,
        })
        .add(Flip.fit('.i', '.on-screen', FLIP_OPTS))
        .add(Flip.fit('.k', '.off-screen--left .right-long', FLIP_OPTS), '<')
        .add(Flip.fit('.l', '.off-screen--bottom', FLIP_OPTS), '<')
    )
    // Tenth Transition
    .add(
      gsap
        .timeline({
          delay: 1,
        })
        .add(Flip.fit('.i', '.on-screen .top-left', FLIP_OPTS))
        .add(Flip.fit('.m', '.on-screen .bottom-left', FLIP_OPTS), '<')
        .add(Flip.fit('.n', '.on-screen .right-long', FLIP_OPTS), '<')
    )
    // Eleventh Transition
    .add(
      gsap
        .timeline({
          delay: 1,
        })
        .add(Flip.fit('.i', '.on-screen', FLIP_OPTS))
        .add(Flip.fit('.m', '.off-screen--bottom', FLIP_OPTS), '<')
        .add(Flip.fit('.n', '.off-screen--right .left-long', FLIP_OPTS), '<')
    )
    // Twelth Transition
    .add(
      gsap
        .timeline({
          delay: 1,
        })
        .add(Flip.fit('.i', '.on-screen .bottom-right', FLIP_OPTS))
        .add(Flip.fit('.o', '.on-screen .top-right', FLIP_OPTS), '<')
        .add(Flip.fit('.p', '.on-screen .left-long', FLIP_OPTS), '<')
    )
    // Thirteenth Transition
    .add(
      gsap
        .timeline({
          delay: 1,
        })
        .add(Flip.fit('.a', '.on-screen', FLIP_OPTS))
        .add(Flip.fit('.i', '.off-screen--left .bottom-right', FLIP_OPTS), '<')
        .add(Flip.fit('.o', '.off-screen--left .top-right', FLIP_OPTS), '<')
        .add(Flip.fit('.p', '.off-screen--left .left-long', FLIP_OPTS), '<')
    )

// const DURATION = 1
let MAIN
let LOOP_HEAD
let TRIGGER
let iteration = 0

setFlips()
MAIN = genFlips()
const START_TIME = 0
const END_TIME = MAIN.duration()

const PLAYHEAD = {
  position: 0,
}

const genLoop = () =>
  gsap.fromTo(
    MAIN,
    {
      totalTime: START_TIME,
    },
    {
      totalTime: END_TIME,
      duration: END_TIME * 2,
      repeat: -1,
      paused: true,
      ease: 'none',
    }
  )

LOOP_HEAD = genLoop()

const POSITION_WRAP = gsap.utils.wrap(0, LOOP_HEAD.duration())

const SCRUB = gsap.to(PLAYHEAD, {
  position: 0,
  paused: true,
  onUpdate: () => {
    LOOP_HEAD.totalTime(POSITION_WRAP(PLAYHEAD.position))
  },
  duration: 0.25,
  ease: 'none',
})

const WRAP = (iterationDelta, scrollTo) => {
  iteration += iterationDelta
  TRIGGER.scroll(scrollTo)
  TRIGGER.update()
}

const genTrigger = () =>
  ScrollTrigger.create({
    start: 0,
    end: '+=10000',
    pin: '.scene',
    scrub: 0.5,
    onUpdate: self => {
      const SCROLL = self.scroll()
      if (SCROLL > self.end - 1) {
        // Go forwards in time
        WRAP(1, 1)
      } else if (SCROLL < 1 && self.direction < 0) {
        // Go backwards in time
        WRAP(-1, self.end - 1)
      } else {
        SCRUB.vars.position = (iteration + self.progress) * LOOP_HEAD.duration()
        SCRUB.invalidate().restart()
      }
    },
  })

TRIGGER = genTrigger()

window.addEventListener(
  'resize',
  debounce(() => {
    MAIN.kill()
    setFlips()
    MAIN = genFlips()
    LOOP_HEAD.kill()
    LOOP_HEAD = genLoop()
    TRIGGER = genTrigger()
  }, 250)
)

              
            
!
999px

Console