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 is required to process package imports. If you need a different preprocessor remove all packages first.

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

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

              
                
              
            
!

CSS

              
                
              
            
!

JS

              
                /* ≻ 사용법 ≺

   // 간편한 사용법
   A11y.toggleButtonControl(토글버튼, 제어대상, ?이벤트핸들러, ?옵션)
   
   // 직접 제어
   const a11yAnim = A11y.playStopAnimation(옵션)
   a11yAnim.toggleAnimationState(상태, 활성클래스)
   a11yAnim.detectAnimationState(상태, 활성클래스)


  // 옵션 설정
  animationId                      : 애니메이션 상태 ID
  activeClass                      : 활성 클래스 이름
  initCallback(state, activeClass) : 초기 실행 시 실행되는 함수 (상태, 활성 클래스)

  // A11y 기본 옵션 사용
  const a11yAnim = A11y.playStopAnimation()

  // 사용자 정의 옵션 설정 사용
  const a11yAnim = A11y.playStopAnimation({
    animationId: 'a11y-play-stop-animation',
    activeClass: 'animation-on',
    initCallback(state, activeClass) {
      console.log(state, activeClass)
    }
  })

*/


class A11y {
  
  // STATIC
  static defaultOptions = {
    animation: {
      animationId:'animation-state', 
      activeClass:'is-animate',
      initCallback:(state, className) => { 
        console.info(`애니메이션 활성화 상태: ${state}, 애니메이션 토글 클래스 이름: ${className}`) 
      }
    }
  }
  static playStopAnimation(options) {
    const {animationId, activeClass, initCallback} = Object.assign({}, A11y.defaultOptions.animation, options)
    const a11yInstance = new A11y()
    a11yInstance._ANIMATE_STATE = animationId
    a11yInstance._ANIMATE_CLASS = activeClass
    if (!a11yInstance._getAnimationState()) {
      a11yInstance._setAnimationState('on')
    }
    a11yInstance.detectAnimationState(initCallback)
    return a11yInstance
  }
  static toggleButtonControl(buttonSelector, targetSelector, callback=()=>{}, options ) {
    if (!buttonSelector || !targetSelector) {
      throw new Error('토글 버튼, 컨트롤 대상 선택자를 입력해주세요.')
    }
    const a11yAnim = A11y.playStopAnimation(options)
    const button = document.querySelector(buttonSelector)
    const targets = document.querySelectorAll(targetSelector)
    if (!button || !targets[0]) {
      throw new Error('토글 버튼 또는 컨트롤 대상이 문서에 존재하지 않습니다.')
    }
    const domControl = (state, activeClass) => {
      if (state === 'on') {
        targets.forEach(target => target.classList.add(a11yAnim._ANIMATE_CLASS))
        button.textContent = '애니메이션 끄기'
      } else {
        targets.forEach(target => target.classList.remove(a11yAnim._ANIMATE_CLASS))
        button.textContent = '애니메이션 켜기'
      }
      callback(button, a11yAnim._getAnimationState())
    }
    button.addEventListener('click', () => {
      a11yAnim.toggleAnimationState(domControl)
    })
    a11yAnim.detectAnimationState(domControl)
    return a11yAnim
  }

  // PRIVATE
  _getAnimationState() {
    return localStorage.getItem(this._ANIMATE_STATE)
  }
  _setAnimationState(value) {
    localStorage.setItem(this._ANIMATE_STATE, value)
  }

  // PUBLIC
  toggleAnimationState(callback) {
    if ( this._getAnimationState() === 'on' ) {
      this._setAnimationState('off')
    } else {
      this._setAnimationState('on')
    }
    this.detectAnimationState(callback)
  }
  detectAnimationState(callback) {
    callback.call(this, this._getAnimationState(), this._ANIMATE_CLASS)
  }

}
              
            
!
999px

Console