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

              
                h1.header SLIDE FILTER
.container
	.filter
		span.filter__item.filter__item--active week
		span.filter__item month
		span.filter__item year
		.filter__switch
	
              
            
!

CSS

              
                $fontPrimary: #a3a7c6
$fontFamily: 'Open Sans Condensed', sans-serif

html
	background: #2d3047

html,
body 
	box-sizing: border-box
	margin: 0
	padding: 0

*, 
*::before, 
*::after
	box-sizing: inherit


h1
	color: $fontPrimary
	font-family: $fontFamily
	text-align: center
	font-size: 4rem


.container
	display: flex
	justify-content: center
	align-items: center
	width: 500px
	height: 200px
	margin: 0 auto

.filter
	width: 100%
	height: 100%
	position: relative
	width: 320px
	height: 60px
	border-radius: 100px
	background: #373b56
	display: flex
	justify-content: space-between
	align-items: center

.filter__item
	width: 33.33%
	font-family: $fontFamily
	font-size: 0.9rem
	text-transform: uppercase
	letter-spacing: 2px
	text-align: center
	color: $fontPrimary
	cursor: pointer
	transition: color 700ms ease
	z-index: 2


.filter__item.active
	color: #fff
	
.filter__switch
	height: calc(100% - 10px)
	width: calc(33.33% - 10px)
	border-radius: 100px
	background: #5a6be8
	position: absolute
	top: 5px
	left: 5px
              
            
!

JS

              
                const filterSwitch = document.querySelector('.filter__switch')

// event delegator for .filter__items
document.querySelector('.filter').addEventListener('click', e => {
  e.stopPropagation()

  const el = e.target

	// if clicked element is an inactive .filter__item
  if (el.classList.contains('filter__item') && !el.classList.contains('filter__item--active')) {
    const filterItemData = el.getBoundingClientRect()
    const switchData = filterSwitch.getBoundingClientRect()
    const origin = document.querySelector('.filter__item').getBoundingClientRect().x + 5

		// calculate new x coordinate for switch
    const midPoint = filterItemData.x + (filterItemData.width / 2)
    const newSwitchX = midPoint - (switchData.width / 2)

		
		// Using the Web Animations API
    const keyframes = [
      { transform: `translateX(${switchData.x - origin}px)`},
      { transform: `translateX(${newSwitchX - origin}px)`}
    ]

    const options = {
      duration: 300,
      easing: 'cubic-bezier(0.42, 0, 0.58, 1)',
      fill: 'forwards'
    }

    filterSwitch.animate(keyframes, options)
		
		// update active .filter__item
    document.querySelector('.filter__item--active').classList.remove('filter__item--active')
    el.classList.add('filter__item--active')
  }
})

              
            
!
999px

Console