css Audio - Active file-generic CSS - Active Generic - Active HTML - Active JS - Active SVG - Active Text - Active file-generic Video - Active header Love html icon-new-collection icon-person icon-team numbered-list123 pop-out spinner split-screen star tv

Pen Settings

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

You're using npm packages, so we've auto-selected Babel for you here, which we require to process imports and make it all work. If you need to use a different JavaScript preprocessor, remove the packages in the npm tab.

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

Use npm Packages

We can make npm packages available for you to use in your JavaScript. We use webpack to prepare them and make them available to import. We'll also process your JavaScript with Babel.

⚠️ This feature can only be used by logged in users.

Code Indentation

     

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.

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.

            
              #proxy
#pageProxy

/#backdrop
  h1 Modeless responsive bi-directional scrolling ZUI for vertical documents

#canvas-container
  #canvas
    .section
      .section-heading Category 1
      - 3.times do
        .box
          - rand(2..8).times do
            p Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.
    .section
      .section-heading Category 2
      - 5.times do
        .box
          - rand(2..8).times do
            p Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.
    .section
      .section-heading Category 3
      - 5.times do
        .box
          - rand(2..8).times do
            p Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.
            
          
!
            
              html
  background: #241338
  color: #c2b5d1
  line-height: 1.414

body
  scroll-snap-type: mandatory
  scroll-snap-points-x: repeat(100vw)
  scroll-snap-points-y: repeat(1px)
  
#proxy
  width: 13*100vw
  height: 100vh + 150vh
  
#pageProxy
  height: 200vh
  
#backdrop
  position: fixed
  left: 0
  top: 0
  right: 0
  
  h1
    color: #c2b5d1
    font-size: 4vmin
    text-align: center
    padding: 0.5em 2em

#canvas-container
  perspective: 100vh
  perspective-origin: center 23.6%
  position: fixed
  left: 0
  top: 0
  right: 0
  bottom: 0
  overflow: hidden
  
#canvas
  white-space: nowrap
  width: 13*100vw
  transform-origin: top
  //will-change: transform

.section
  display: inline-block
  position: relative
  
.section-heading
  position: absolute
  left: 0
  right: 0
  top: -2em
  line-height: 1
  font-size: 4em
  color: #d1cab5
  background: #241338
  font-weight: bold
  padding: 0.5em
  
.box
  vertical-align: top
  white-space: normal
  box-sizing: border-box
  background: #3a1e5a
  padding: 1.618em
  font-size: 1.618em
  width: 100vw
  display: inline-block
  border: 2vw solid #241338
  
p
  margin: 0
  
p + p 
  margin-top: 1.414em
            
          
!
            
              snapDuration = 162

browser = $(window)
body = $("body")
proxy = $("#proxy")
pageProxy = $("#pageProxy")
canvas = $("#canvas")
boxes = $(".box")

windowWidth = browser.width()
windowHeight = browser.height()
width = body[0].scrollWidth
height = body[0].scrollHeight
perspective = windowHeight
proxyHeight = proxy.height()
x = 0

targetBox = undefined
targetBoxIndex = 0

#if 'scrollSnapType' in document.documentElement.style || 'webkitScrollSnapType' in document.documentElement.style
#  isScrollSnapSupported = true
#else
#  isScrollSnapSupported = false

browser.on "scroll", (event) ->
  requestAnimationFrame(positionStuff)

browser.resize (event) ->
  setStuff()
  requestAnimationFrame(positionStuff)

#boxes.on "click", ->
  # TODO: trigger snapScrollTo here

transitionTimeout = null # set later
canvas.on "transitionEnd webkitTransitionEnd", ->
  canvas.css
    "-webkit-transition": "none"
    "transition":         "none"
  
$ ->
  setStuff() 
  requestAnimationFrame(positionStuff)
  
setStuff = ->
  boxes = $(".box")
  windowWidth = browser.width()
  windowHeight = browser.height()
  width = body[0].scrollWidth
  height = body[0].scrollHeight
  perspective = windowHeight
  proxyHeight = proxy.height()
  
positionStuff = ->
  left = browser.scrollLeft()
  top = browser.scrollTop()
  leftRatio = left / width
  topRatio  = top  / (proxyHeight-windowHeight)
  
  newX = (-leftRatio*width)
  deltaX = x - newX
  x = newX
  z = (-perspective*2.5 + topRatio*perspective*2.5)
  
  if z > 0
    newTargetBoxIndex = Math.round(leftRatio * boxes.length)
    newTargetBox = boxes[newTargetBoxIndex]
    unless targetBox == newTargetBox
      targetBox = newTargetBox
      pageProxy.height($(targetBox).height())
    z = 0
    y = -top + proxyHeight - windowHeight
  else
    y = 0
    
  canvas.css
    "-webkit-transform": "translate3d(#{x}px, #{y}px, #{z}px)"
    "transform":         "translate3d(#{x}px, #{y}px, #{z}px)"

snapScrollTo = (index) ->
  console.log "snapScrolling"
  newX = windowWidth * index
  deltaX = Math.abs(x + newX)
  transitionDuration = deltaX / 1000
  canvas.css
    "-webkit-transition": "-webkit-transform #{transitionDuration}s ease-out"
    "transition":         "transform         #{transitionDuration}s ease-out"
  transitionTimeout = window.setTimeout ->
    canvas.css
      "-webkit-transition": "none"
      "transition":         "none"
  , transitionDuration*1000
  browser.scrollLeft(newX)
      
snapScrolling = ->
  leftRatio = browser.scrollLeft() / width
  newTargetBoxIndex = Math.round(leftRatio * boxes.length)
  unless browser.scrollLeft() == newTargetBoxIndex*windowWidth
    snapScrollTo(newTargetBoxIndex)
    
browser.on("scroll", _.debounce(snapScrolling, 100)) 
browser.on("resize", _.debounce(snapScrolling, 100))    
            
          
!
999px
🕑 One or more of the npm packages you are using needs to be built. You're the first person to ever need it! We're building it right now and your preview will start updating again when it's ready.
Loading ..................

Console