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

              
                <div class="Gallery">
  <div class="Gallery-wrapper">
    <div class="Gallery-container js-container">
      <div class="Gallery-item js-item">
        <div class="Gallery-itemContent">1</div>
      </div>
      <div class="Gallery-item js-item">
        <div class="Gallery-itemContent">2</div>
      </div>
      <div class="Gallery-item js-item">
        <div class="Gallery-itemContent">3</div>
      </div>
      <div class="Gallery-item js-item">
        <div class="Gallery-itemContent">4</div>
      </div>
      <div class="Gallery-item js-item">
        <div class="Gallery-itemContent">5</div>
      </div>
      <div class="Gallery-item js-item">
        <div class="Gallery-itemContent">6</div>
      </div>
      <div class="Gallery-item js-item">
        <div class="Gallery-itemContent">7</div>
      </div>
    </div>
  </div>
</div>

<div class="Nav js-nav">
  <button class="Nav-button js-button"></button>
  <button class="Nav-button js-button"></button>
  <button class="Nav-button js-button"></button>
  <button class="Nav-button js-button"></button>
  <button class="Nav-button js-button"></button>
  <button class="Nav-button js-button"></button>
  <button class="Nav-button js-button"></button>
</div>
              
            
!

CSS

              
                :root {
  --button-size: 22px;
  --button-offset: 22px;
  --border-color: #00e;

  --button-size-md: 30px;
  --button-offset-md: 30px;

  --gallery-item-size: 300px;
  --gallery-item-size-md: 500px;
}

html {
  box-sizing: border-box;
  height: 100%;
}

*, *::before, *::after {
  box-sizing: inherit;
}

body {
  align-items: center;
  background-color: #fee01e;
  display: flex;
  flex-direction: column;
  height: 100%;
  justify-content: center;
  font-family: 'Monda', sans-serif;
  font-weight: 700;
  margin: 0;
  padding: 0;
  width: 100%;
}

.Nav {
  display: flex;
  position: relative;
  padding: 5px; /* leave room for SVG stroke */
}

.Nav svg {
  position: absolute;
  top: 0;
  left: 0;
}

.Nav-button {
  background-color: transparent;
  border-radius: 50%;
  border: none;
  cursor: pointer;
  overflow: hidden;
  padding: 0;
  position: relative;
  height: var(--button-size);
  width: var(--button-size);
  border-radius: 50%;
  border: 2px solid var(--border-color);
  z-index: 1;
}

.Nav-button:not(:first-child) {
  margin-left: var(--button-offset);
}

@media (min-width: 600px) {
  .Nav-button {
    height: var(--button-size-md);
    width: var(--button-size-md);
  }

  .Nav-button:not(:first-child) {
    margin-left: var(--button-offset-md);
  }
}

.Nav-button:focus {
  outline: none;
}


.Gallery-wrapper {
  width: var(--gallery-item-size);
  overflow: hidden;
}

.Gallery {
  position: relative;
  margin-bottom: 30px;
}

.Gallery::before {
  content: '';
  position: absolute;
  top: 10px;
  left: 10px;
  width: 100%;
  height: 100%;
  background-color: #00e;
}

.Gallery-container {
  display: flex;
  transition-property: transform;
  transition-duration: 600ms;
  transition-timing-function: cubic-bezier(0.8, 0, 0.55, 0.94);
}

.Gallery-item {
  flex-shrink: 0;
  padding-right: 20px;
}

.Gallery-itemContent {
  width: var(--gallery-item-size);
  height: calc(var(--gallery-item-size) * .56);
  background-color: #FFF;
  border: 2px solid #00e;
  color: #00e;
  display: flex;
  justify-content: center;
  align-items: center;
  font-size: 68px;
  position: relative;
}



@media (min-width: 600px) {
  .Gallery-wrapper {
    width: var(--gallery-item-size-md);
  }
  .Gallery-itemContent {
    width: var(--gallery-item-size-md);
    height: calc(var(--gallery-item-size-md) * .56);
    font-size: 96px;
  }
}

              
            
!

JS

              
                class FancyNav {
  constructor ({ btns, nav, highlightColor, backgroundColor, strokeWidth }) {
    this.btns = btns
    this.nav = nav
    this.highlightColor = highlightColor
    this.strokeWidth = strokeWidth
    this.backgroundColor = backgroundColor
    this.transparent = this.alphaFromColor(highlightColor, 0)
  }

  render () {
    const svg = Snap(this.nav.clientWidth, this.nav.clientHeight)
    this.svgBtns = this.btns.map(btn => this.renderSVGBtns(btn, svg))

    const btnBBox = this.svgBtns[0].getBBox()
    this.offset = this.svgBtns[1].getBBox().cx - btnBBox.cx
    this.magicPath = this.renderMagicPath(svg, btnBBox)
    this.circumference = 2 * Math.PI * btnBBox.r1 // assume circle

    this.setCurrent()
    this.bindBtnEvents()
    this.nav.appendChild(svg.node)
  }

  renderSVGBtns (btn, svg) {
    // Hide html btns
    btn.style.opacity = 0
    const x = btn.offsetLeft + btn.offsetWidth / 2
    const y = btn.offsetTop + btn.offsetHeight / 2
    const r = btn.offsetHeight / 2 // assume circle

    const outerCircle = svg
      .circle(x, y, r)
      .attr({
        fill: this.transparent,
        stroke: this.highlightColor,
        strokeWidth: 2
      })
    const innerCircle = svg
      .circle(x, y, r / 4)
      .attr({
        fill: this.highlightColor,
        stroke: this.transparent,
        strokeWidth: 0,
        class: 'hoverIndicator',
        transform: 's0,0'
      })

    return svg.group(outerCircle, innerCircle)
  }

  renderMagicPath (svg, btnBBox) {
    const pathSegments = [
      `M${btnBBox.cx},${btnBBox.y2}`
    ].concat(
      this.svgBtns.reduce((acc, b, index, arr) => {
        const res = [
          `a${btnBBox.r1},${btnBBox.r1},0,0,0,0,-${btnBBox.height}`, // left circle
          `a${btnBBox.r1},${btnBBox.r1},0,0,0,0,${btnBBox.height}` // right circle
        ]
        if (index < arr.length - 1) {
          res.push(`l${this.offset},0`) // path to next circle, not on last one
        }
        return acc.concat(res)
      }, [])
    )

    return svg
      .path(pathSegments.join(' '))
      .attr({
        stroke: this.highlightColor,
        strokeWidth: this.strokeWidth,
        strokeLinecap: 'round',
        fill: this.transparent
      })
  }

  setCurrent () {
    const pathLength = Snap.path.getTotalLength(this.magicPath.attr('d')) // fixes length in Firefox
    // strokeDasharray: `${this.circumference - this.strokeWidth / 4}, ${pathLength}`,
    this.magicPath.attr({
      strokeDasharray: `${this.circumference - this.strokeWidth / 4}, ${pathLength}`,
      strokeDashoffset: 0
    })
  }

  goToIndex (index) {
    const dashOffset = -index * (this.circumference + this.offset)
    Snap.animate(this.removePx(this.magicPath.attr('strokeDashoffset')), dashOffset, v => {
      this.magicPath.attr({ strokeDashoffset: v })
    }, 600, mina.easeinout )
  }

  bindBtnEvents () {
    this.btns.forEach((btn, index) => {
      btn.addEventListener('click', () => this.handleClick(index), false)
      btn.addEventListener('mouseover', () => this.showFocus(index), false)
      btn.addEventListener('focus', () => this.showFocus(index), false)
      btn.addEventListener('mouseout', () => this.removeFocus(index), false)
      btn.addEventListener('blur', () => this.removeFocus(index), false)
    })
  }

  showFocus (index) {
    this.svgBtns[index]
      .select('.hoverIndicator')
      .stop()
      .animate({ transform: 's1,1' }, 225, mina.easein)
  }

  removeFocus (index) {
    this.svgBtns[index]
      .select('.hoverIndicator')
      .stop()
      .animate({ transform: 's0,0' }, 175, mina.easeout)
  }

  handleClick (index) {
    this.goToIndex(index)
  }

  removePx (str) {
    return parseInt(str.replace('px', ''), 10)
  }

  alphaFromColor (c, alpha) {
    const {r, g, b} = Snap.color(c)
    return `rgba(${r}, ${g}, ${b}, ${alpha})`
  }
}

class Gallery {
  constructor ({ container, items, btns, nav }) {
    this.container = container
    this.items = items
    this.btns = btns
    this.nav = nav
    this.itemWidth = this.items[0].clientWidth
  }

  render () {
    this.btns.forEach((btn, index) => {
      btn.addEventListener('click', () => this.goToIndex(index), false)
    })

    const fancyNav = new FancyNav({
      btns: this.btns,
      nav: this.nav,
      highlightColor: '#00e',
      backgroundColor: '#FFFFFF',
      strokeWidth: 10
    }).render()
  }

  goToIndex (index) {
    this.container.style.transform = `translateX(${-index * this.itemWidth}px)`
  }
}

const gallery = new Gallery({
  container: document.querySelector('.js-container'),
  nav: document.querySelector('.js-nav'),
  items: Array.from(document.querySelectorAll('.js-item')),
  btns: Array.from(document.querySelectorAll('.js-button'))
}).render()

              
            
!
999px

Console