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

              
                div.container
  button Toggle
  ul.block
    li Vanilla JS
    li 60 FPS

//- div.container
//-   button Toggle
//-   ul.block.with-padding
//-     li One
//-     li Two
    

div.container
  button Toggle
  ul.block.with-border
    li One
    li Two
    li Three
    li Four
    
div.container
  button Toggle
  ul.block.hidden
    li One
    li Two
    li Three
              
            
!

CSS

              
                body
  display: flex
  min-height: 100vh
  justify-content: space-around
  align-items: flex-start
  background: linear-gradient(to right top, #000000, #e5008d, #ff070b)
  user-select: none
  font-family: 'Titillium Web', sans-serif
    
.container
  text-align: center
  margin: 40px
  flex: 1
  
button
  background: black
  border: black
  width: 100%
  color: white
  border-radius: .125em
  font: inherit
  padding: .75em 1em
  text-transform: uppercase
  letter-spacing: .1em
  box-shadow: 0 2px 3px 0 rgba(black,.5)
  cursor: pointer

.block
  background: black  
  box-shadow: 0 2px 3px 0 rgba(black,.5)
  
  text-align: left
  font-size: 1.25em
  color: white
  
  list-style-type: none
  overflow: hidden
  padding: 0
  white-space: nowrap
  letter-spacing: .1em
    
  &.with-padding
    padding: 5em 0
    // box-sizing: border-box
    
  &.with-border
    border:
      top: 1px solid magenta
      bottom: 2px solid magenta
  
  &.hidden
    display: none
      
  li
    padding: 1em .5em
    margin: 0 1em
    + li
      border-top: 1px solid white
              
            
!

JS

              
                class slideToggler
  
  constructor: (@el) ->
    
    return unless @el

    window.addEventListener 'resize', @getHeight
  
  getHeight: =>
    clone = @el.cloneNode(true)
    clone.style.cssText = 'visibility: hidden; display: block; margin: -999px 0'
    @height = (@el.parentNode.appendChild clone).clientHeight
    @el.parentNode.removeChild(clone)
    return @height
  
  toggle: (time) =>
    @getHeight()
    time or= @height / 3 + 150
    currHeight = @el.clientHeight * (getComputedStyle(@el).display != 'none')
    [start, end] = if currHeight > @height/2 then [@height,0] else [0,@height]
    disp = end - start
    el = @el
    
    @el.classList[ if end is 0 then 'remove' else 'add' ] 'open'
    @el.style.cssText = "overflow: hidden; display: block;"

    init = (new Date).getTime()

    repeat = ->
      instance = (new Date).getTime() - init
      step = start + disp * instance / time
      if instance <= time
        el.style.height = step + 'px' # if Math.floor(step) in [start..end]
      else
        el.style.cssText = "display: #{if end is 0 then 'none' else 'block'}"

      repeatLoop = requestAnimationFrame(repeat)
      cancelAnimationFrame repeatLoop unless Math.floor(step) in [start..end]
      
    repeat()
    
for block in document.querySelectorAll('.block')
  block.toggler = new slideToggler block

for trigger in document.querySelectorAll('button')
  trigger.addEventListener 'click', ->
    @parentNode.querySelector('.block').toggler?.toggle()


              
            
!
999px

Console