Skip to content

huangbohang/shake_notice

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

5 Commits
 
 
 
 
 
 

Repository files navigation

元素抖动提醒

  • 安装
    • npm install shake_notice -D
  • 导入
    • import 'shake_notice'
  • 直接使用
<button class="apply-shake"></button>
  • Vue2 封装成自定义指令
Vue.directive('shake', {
  bind(el, binding) {
    el.addEventListener('animationend', (e) => {
      el.classList.remove('apply-shake')
    })
    if (binding.value) {
      el.classList.add('apply-shake')
    }
  },
  update(el, binding) {
    if (binding.value) {
      el.classList.add('apply-shake')
    }
  }
})
  • 使用
<template>
  <div>
    <button v-shake="isShake">抖动元素</button>
    <button @click="emitShake">点击按钮</button>
  </div>
</template>

<script>

export default {
  data() {
    return {
      isShake: false
    }
  },
  methods: {
    emitShake() {
      this.isShake = false
      this.isShake = true
    }
  }
}
</script>

About

抖动提醒

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages