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

              
                h1 Collapse/Accordion 套件

hr

h2 Default Set, click the title and the content slideUp/slideDown
dl.modules-collapse
  dt.active title1
  dd content1
  dt title2
  dd content2
  dt title3
  dd content3

hr

h2 Add 「class="-keep"」, keep before content slideDown
dl.modules-collapse.-keep
  dt.active title4
  dd content4
  dt title5
  dd content5
  dt title6
  dd content6

              
            
!

CSS

              
                @import compass/reset
@import compass

// body、h1、h2、content color set
$font-color: rgba(#263238, .87) !default

// collpase/accordion color set
$collapse-border: 1px solid #607D8B !default
$collapse-title-bg: #CFD8DC !default
$collapse-title-bg-active: #607D8B !default
$collapse-title-color-active: rgba(white, .87) !default
$collapse-content-bg: #FFF !default

// transition default
%trnasition-default
  +transition(.5s cubic-bezier(.3, .1, .05, 1))

// default padding: 16px
%padding
  padding: 16px

// base set
*, *::before, *::after
  +box-sizing(border-box)

body
  @extend %padding
  background-color: #ECEFF1
  font-family: \5FAE\8EDF\6B63\9ED1\9AD4, Microsoft JhengHei, MingLiU, sans-serif

h1
  text-align: center
  +adjust-font-size-to(3rem)
  color: $font-color

h2
  padding-bottom: 4px
  +adjust-font-size-to(1.5rem)
  color: $font-color

hr
  margin: 11px 2rem 12px
  border: 0
  border-top: 1px solid lighten(#555 ,46)

// collapse/accordion set
.modules-collapse
  background-color: #ECEFF1
  // title set
  > dt
    position: relative
    z-index: 1
    @extend %padding
    overflow: hidden
    background-color: $collapse-title-bg
    border: $collapse-border
    color: $font-color
    cursor: pointer
    @extend %trnasition-default
    // 背景色特效 bg transform
    &::before
      content: ""
      position: absolute
      // 清掉border帶來的1px,所以是-1px
      top: -1px
      right: -1px
      bottom: -1px
      left: -1px
      z-index: -1
      background-color: $collapse-title-bg-active
      +transform(scaleY(0))
      +transform-origin(0, 0)
      @extend %trnasition-default
    // 「+」符號
    &::after
      font-family: "FontAwesome"
      content: "\f067"
      position: absolute
      right: 16px
  // hover transform
  > dt:hover
    &::before
      +transform(scaleY(.1))
    &::after
      content: "\f1ce"
      +animation(fa-spin 2s infinite linear)
  // .active set
  > dt.active
    color: $collapse-title-color-active
    // 背景色特效
    &::before
      +transform(scaleY(1))
    // 「-」符號
    &::after
      content: "\f068"
      +animation(none)
  // content set
  > dd
    display: none
    @extend %padding
    background-color: $collapse-content-bg
    border: $collapse-border
    color: $font-color
  // 頭跟尾的圓角 top & bottom border-radius
  > dt:first-child
    &, &:hover, &::before
      +border-top-radius(8px)
  > dd:last-child
    +border-bottom-radius(8px)
              
            
!

JS

              
                $(function() {
  var $title = $('.modules-collapse > dt');
  var $content = $('.modules-collapse > dt.active').next('dd');
  
  $content.slideDown();
  
  $title.click(function() {
    // 讓每一組collapse都可以分開使用
    var $modulesTitle = $(this).closest('.modules-collapse');
    
    // 設定共同展開速度
    var slideSpeed = 500;
    
    // .-keep的設定
    if($modulesTitle.hasClass('-keep')) {
      $(this).toggleClass('active');
      if($(this).hasClass('active')) {
        $(this).next('dd').stop().slideDown(slideSpeed);
      }
      else {
        $(this).next('dd').stop().slideUp(slideSpeed);
      }
    }
    
    // not .-keep的設定
    else {
      // 若原本已經是展開的,則收闔
      if($(this).hasClass('active')) {
        $(this).next('dd').stop().slideUp(slideSpeed).end().removeClass('active');
      }
      else {
        $modulesTitle.find('.active').next('dd').stop().slideUp(slideSpeed).end().removeClass('active');

        // 被點擊到的展開
        $(this).addClass('active').next('dd').stop().slideDown(400);
      }
    }
  });
});
              
            
!
999px

Console