Home

Awesome

vue-particle-effect-buttons (demo)

All Contributors Codacy Badge Greenkeeper badge Build Status Known Vulnerabilities License: MIT npm

Bursting particle effect buttons for Vue.

This library is a Vue portal of an awesome Codrops Article by Luis Manuel (original source).

Install

npm install --save animejs vue-particle-effect-buttons

Usage

Check out the Demo to see it in action.

<template>
    <ParticleBtn
      :visible.sync="btnOps.visible"
      :animating.sync="btnOps.animating"
      :options="btnOps"
      cls="btn-cls"
    >
    hello eveybody!
    </ParticleBtn>
    <h2>animating:{{btnOps.animating}}</h2>
    <h2>visible:{{btnOps.visible}}</h2>
    <button @click="btnOps.visible=!btnOps.visible">toggle</button>
  </div>
</template>

<script>
import ParticleEffectButton from "vue-particle-effect-buttons"

export default {
  data() {
    return {
      btnOps: {
        type: "triangle",
        easing: "easeOutQuart",
        size: 6,
        particlesAmountCoefficient: 4,
        oscillationCoefficient: 2,
        color: function () {
          return Math.random() < 0.5 ? "#000000" : "#ffffff";
        },
        onComplete: () => {
          console.log("complete");
        },
        onBegin: () => {
          console.log("begin");
        },
        visible: true,
        animating: false
      },
    }
  },
  components: {
    ParticleEffectButton
  }
};
</script>

Note that children can be anything, The children should represent the button's contents.

You change the visible boolean prop to kick-off an animation, typically as a result of a click on the button's contents. If visible changes to false, the button will perform a disintegrating animation. If visible changes to true, it will reverse and reintegrate the original content.

Props

PropertyTypeDefaultDescription
visiblebooleantrueWhether button should be hidden or visible. Changing this prop starts an animation. support .sync modifier
animatingbooleanfalseGet the current status of animating or end of the animation. support .sync modifier
clsstring/Object/ArrarnoopThe class to change the default button styles
durationnumber1000Animation duration in milliseconds.
easingstring'easeInOutCubic'Animation easing.
typestringcircle'circle' or 'rectangle' or 'triangle'
stylestringfill'fill' or 'stroke'
directionstring'left''left' or 'right' or 'top' or 'bottom'
canvasPaddingnumber150Amount of extra padding to add to the canvas since the animation will overflow the content's bounds
sizenumberfuncrandom(4)
speednumberfuncrandom(4)
particlesAmountCoefficientnumber3Increases or decreases the relative number of particles
oscillationCoefficientnumber20Increases or decreases the relative curvature of particles
onBeginfuncnoopCallback to be notified once an animation starts.
onCompletefuncnoopCallback to be notified once an animation completes.

I tried to keep the properties exactly the same as in the original codrops version.

Slots

PropertyTypeDefaultDescription
defaultslotthe string of 'content'the content of the button

Related

Contributors

Thanks goes to these wonderful people (emoji key):

<!-- ALL-CONTRIBUTORS-LIST:START - Do not remove or modify this section --> <!-- prettier-ignore --> <table><tr><td align="center"><a href="https://dreambo8563.github.io/"><img src="https://avatars2.githubusercontent.com/u/6948318?v=4" width="100px;" alt="Vincent Guo"/><br /><sub><b>Vincent Guo</b></sub></a><br /><a href="https://github.com/dreambo8563/vue-particle-effect-buttons/commits?author=dreambo8563" title="Code">💻</a> <a href="https://github.com/dreambo8563/vue-particle-effect-buttons/commits?author=dreambo8563" title="Documentation">📖</a> <a href="#infra-dreambo8563" title="Infrastructure (Hosting, Build-Tools, etc)">🚇</a></td></tr></table> <!-- ALL-CONTRIBUTORS-LIST:END -->

This project follows the all-contributors specification. Contributions of any kind welcome!