Pen Settings



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


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


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.


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.


                //- PREVIOUS VERSION:

- var placeholder = function(width, height) { return "data:image/svg+xml;charset=utf-8,%3Csvg%20xmlns%3D''%20viewBox%3D'0%200%20" + width + "%20" + height + "'%20%2F%3E" }

- var images = [{ id: '-gS54SWrHMg', width: 1000, height: 500 },{id: 'AU1rKyKPJco', width: 500, height: 1000, caption: 'Hello from Poland' },{ id: 'AXfDvKOawZQ' },{ id: 'gKlkZrsG_Pw', width: 1000, height: 500 },{ id: 'DVONaLgCRxo', width: 500, height: 1000 },{ id: 'o7txpYpxNLs', caption: 'Have a nice day' },{ id: 'ZsgUsl8GATg', width: 500, height: 1000, caption: 'This is a very very long description to show you it\'s possible to add something like this' },{ id: 'CkagyZJ88kE' },{ id: 'PpQ4-HOZ_8U', width: 1000, height: 500 },{ id: 'si7gjqJQj_8' },{ id: 'u0M0gyuexfE', width: 500, height: 1000 },{ id: 'aQcE3gDSSTY' },{ id: 'GkCafprWKRo', width: 500, height: 1000 },{ id: 'OFlzoTfpRdw' },{ id: 'YlFM0-LdHu8' },{ id: 'c_Tc9ZELeYw' }]

mixin gallery-item(id, width=500, height=500, caption)
  if height > width
    - var klass = 'vertical' 
  else if width > height
    - var klass = 'horizontal''associatedMedia', itemscope='', itemtype='', class=klass)
    a(href=`${id}/${width*2}x${height*2}`, itemprop='contentUrl', data-size=`${width*2}x${height*2}`)
      img.lazyload.lazypreload.fadein(src=placeholder(width,height) data-src=`${id}/${width}x${height}`, itemprop='thumbnail', alt='Image description')'caption description')= caption || 'Caption'

.gallery(itemscope='', itemtype='')
  each image in images
    +gallery-item(,image.width,image.height, image.caption)
// Root element of PhotoSwipe. Must have class pswp.
.pswp(tabindex='-1', role='dialog', aria-hidden='true')
    Background of PhotoSwipe.
    It's a separate element as animating opacity is faster than rgba().
  // Slides wrapper with overflow:hidden.
      Container that holds slides.
      PhotoSwipe keeps only 3 of them in the DOM to save memory.
      Don't modify these 3 pswp__item elements, data is added later on.
    // Default (PhotoSwipeUI_Default) interface on top of sliding area. Can be changed.
        // Controls are self-explanatory. Order can be changed.
        button.pswp__button.pswp__button--close(title='Close (Esc)')
        button.pswp__button.pswp__button--fs(title='Toggle fullscreen')
        button.pswp__button.pswp__button--zoom(title='Zoom in/out')
        // Preloader demo
        // element will get class pswp__preloader--active when preloader is running
      button.pswp__button.pswp__button--arrow--left(title='Previous (arrow left)')
      button.pswp__button.pswp__button--arrow--right(title='Next (arrow right)')



  +absolute(bottom 4rem left 50%)
  transform: translate(-50%,0%)
  font-size: 12px
    font-size: 14px
  color: rgba(white,0)
  padding: 1.25em 1.5em
  transition: all .2s ease
  font-weight: 600
  // min-width: 10rem
  // width: 50%
  // max-width: calc(100% - 6rem)

  line-height: 1.25
  text-align: center
  box-sizing: border-box
  pointer-events: none

  &:before, &:after
    content: ''
    +absolute(top right left bottom)
    background: rgba(black,1)
    width: 100%
    height: 100%
    transition: all .3s ease 0s
    z-index: -1

    top: auto
    height: 3px
    transform: scale(0,1)
    transform-origin: bottom left
    transition-delay: .6s

    transform: scale(1,0)
    transform-origin: bottom
    transition-delay: .3s

    color: rgba(white,1)
    text-shadow: 0 0 1px rgba(black,.2)
    transition: all .3s ease .3s
      transform: scale(1,1)
      transition-delay: 0s
      transform: scale(1,1)

    display: none

$corner: 1rem

  &:before, &:after
    content: ''
    +absolute(top right left bottom)
    border: 0 solid rgba(black,.1)
    transition: all .2s
    will-change: border
    z-index: 10

      border-width: .5rem
      border-width: 2px
    margin: $corner
    border: 2px solid rgba(white,.5)
    clip-path: polygon(0 calc(100% - #{$corner}), 0 100%, $corner 100%, $corner 0, 0 0, 0 $corner, 100% $corner, 100% 0, calc(100% - #{$corner}) 0, calc(100% - #{$corner}) 100%, 100% 100%, 100% calc(100% - #{$corner}))

      transform: scale(.9)
      border-color: rgba(white,1)

  background-color: black
  color: white
  padding: .75em 1em
  display: inline-block
  text-align: left

  width: 100%
  display: grid
  grid-template-rows: flow
  grid-auto-flow: dense

  +breakpoint(max-width $mobile - 1px)
    grid-template-columns: repeat(2, 1fr)
  +breakpoint($mobile $desktop - 1px)
    grid-template-columns: repeat(3, 1fr)
  +breakpoint($desktop $laptop - px)
    grid-template-columns: repeat(4, 1fr)
  +breakpoint($laptop $screen - 1px)
    grid-template-columns: repeat(5, 1fr)  
    grid-template-columns: repeat(6, 1fr)  
  background-color: rgba(black,.5)
  overflow: hidden
  img, a
    display: block

    grid-row: span 2

    grid-column: span 2
  @extend %gallery-grid

  @extend %gallery-item
    display: block
    @extend %image-border

    .lazy-images &.image-lazyloaded, html:not(.lazy-images) &


  html:not(.touchevents) &
    @extend %gallery-caption

  .gallery-item:hover &
    @extend %gallery-caption.visible

  [class*=list] &, .gallery-size-thumbnail &
    display: none


                initPhotoSwipeFromDOM = (gallerySelector) ->
  # parse slide data (url, title, size ...) from DOM elements 
  # (children of gallerySelector)

  parseThumbnailElements = (el) ->
    thumbElements = el.childNodes
    numNodes = thumbElements.length
    items = []
    figureEl = undefined
    linkEl = undefined
    size = undefined
    item = undefined
    i = 0
    while i < numNodes
      figureEl = thumbElements[i]
      # <figure> element
      # include only element nodes 
      if figureEl.nodeType != 1
      linkEl = figureEl.children[0]
      # <a> element
      size = linkEl.getAttribute('data-size').split('x')
      # create slide object
      item =
        src: linkEl.getAttribute('href')
        w: parseInt(size[0], 10)
        h: parseInt(size[1], 10)
      if figureEl.children.length > 1
        # <figcaption> content
        item.title = figureEl.children[1].innerHTML
      if linkEl.children.length > 0
        # <img> thumbnail element, retrieving thumbnail url
        item.msrc = linkEl.children[0].getAttribute('src')
      item.el = figureEl
      # save link to element for getThumbBoundsFn
      items.push item

  # find nearest parent element

  closest = (el, fn) ->
    el and (if fn(el) then el else closest(el.parentNode, fn))

  # triggers when user clicks on thumbnail

  onThumbnailsClick = (e) ->
    e = e or window.event
    if e.preventDefault then e.preventDefault() else (e.returnValue = false)
    eTarget = or e.srcElement
    # find root element of slide
    clickedListItem = closest(eTarget, (el) ->
      el.tagName and el.tagName.toUpperCase() == 'FIGURE'
    if !clickedListItem
    # find index of clicked item by looping through all child nodes
    # alternatively, you may define index via data- attribute
    clickedGallery = clickedListItem.parentNode
    childNodes = clickedListItem.parentNode.childNodes
    numChildNodes = childNodes.length
    nodeIndex = 0
    index = undefined
    i = 0
    while i < numChildNodes
      if childNodes[i].nodeType != 1
      if childNodes[i] == clickedListItem
        index = nodeIndex
    if index >= 0
      # open PhotoSwipe if valid index found
      openPhotoSwipe index, clickedGallery

  # parse picture index and gallery index from URL (#&pid=1&gid=2)

  photoswipeParseHash = ->
    hash = window.location.hash.substring(1)
    params = {}
    if hash.length < 5
      return params
    vars = hash.split('&')
    i = 0
    while i < vars.length
      if !vars[i]
      pair = vars[i].split('=')
      if pair.length < 2
      params[pair[0]] = pair[1]
    if params.gid
      params.gid = parseInt(params.gid, 10)

  openPhotoSwipe = (index, galleryElement, disableAnimation, fromURL) ->
    pswpElement = document.querySelectorAll('.pswp')[0]
    gallery = undefined
    options = undefined
    items = undefined
    items = parseThumbnailElements(galleryElement)
    # define options (if needed)
    options =
      galleryUID: galleryElement.getAttribute('data-pswp-uid')
      getThumbBoundsFn: (index) ->
        # See Options -> getThumbBoundsFn section of documentation for more info
        thumbnail = items[index].el.getElementsByTagName('img')[0]
        pageYScroll = window.pageYOffset or document.documentElement.scrollTop
        rect = thumbnail.getBoundingClientRect()
          x: rect.left
          y: + pageYScroll
          w: rect.width
    # PhotoSwipe opened from URL
    if fromURL
      if options.galleryPIDs
        # parse real index when custom PIDs are used 
        j = 0
        while j < items.length
          if items[j].pid == index
            options.index = j
        # in URL indexes start from 1
        options.index = parseInt(index, 10) - 1
      options.index = parseInt(index, 10)
    # exit if index not found
    if isNaN(options.index)
    if disableAnimation
      options.showAnimationDuration = 0
    # Pass data to PhotoSwipe and initialize it
    gallery = new PhotoSwipe(pswpElement, PhotoSwipeUI_Default, items, options)

  # loop through all gallery elements and bind events
  galleryElements = document.querySelectorAll(gallerySelector)
  i = 0
  l = galleryElements.length
  while i < l
    galleryElements[i].setAttribute 'data-pswp-uid', i + 1
    galleryElements[i].onclick = onThumbnailsClick
  # Parse URL and open gallery if it contains #&pid=3&gid=1
  hashData = photoswipeParseHash()
  if and hashData.gid
    openPhotoSwipe, galleryElements[hashData.gid - 1], true, true

# execute above function
initPhotoSwipeFromDOM '.gallery'

# ---
# generated by js2coffee 2.2.0