Giter Club home page Giter Club logo

vue-tween's Introduction

Vue Tween

Simple Vue.js library to apply Javascript tweening. Based on jaxgeller/tweezer.js.

Demo

Color Lord

Requirements

  • Vue => 1.x - 2.x
  • and maybe requestAnimationFrame polyfill (for module)

Installation

1) Download the package through npm

npm install vue-tween --save

Note: All codes here will be written in ES6. But that doesn't mean any version or type of Javascript not applicable.

Then install it,

import Vue from 'vue'
import VueTween from 'vue-tween'

Vue.use(VueTween)

There are couple options you can fill in within installation.

  • name : Change the name of the directive.
  • default : Change default value for animation start, end and duration time.
  • easing : Include easing globally.

Example

import Vue from 'vue'
import VueTween from 'vue-tween'

Vue.use(VueTween, {
  name: 'animate', //default: tween
  default: {
    start: -500, //default: 0
    end: 500, //default: 1000
    duration: 2000 //default: 1000
  },
  easing: { // default easing is only easeInOut which is provided by tweezer.js
    easeOutQuad (t, b, c, d) { 
      return -c * (t /= d)*(t - 2) + b;
    }
  }
})

2) With CDN.

Dependency and requestAnimationFrame polyfill already bundled in CDN script. It will also perform an auto-install on Vue.

<script src="https://cdn.rawgit.com/chay22/vue-tween/master/vue-tween.min.js"></script>
<!-- or -->
<script src="https://unpkg.com/[email protected]/vue-tween.min.js"></script>

Usage

<template>
  <div v-tween:click.capture="myTweening">
    <span :style="style"></span>
  </div>
</template>

1) Directive name required

<div v-tween:click.capture="myTweening">

This could be renamed during installation

2) Arguments required

<div v-tween:click.capture="myTweening">

DOM event. For Vue 1.x, it is based on built-in on directive.

3) Modifier

<div v-tween:click.capture="myTweening">

Available modifiers for Vue 1.x are on the docs. For Vue 2.x capture is the only valid modifier.

4) Handler

<div v-tween:click.capture="myTweening">

The handler must return an object containing the following:

  • start integer | default: 0

    Start of tween.

  • end integer | default: 1000

    End of tween.

  • duration integer | default: 1000

    Duration of tween.

  • easing function/string | default: easeInOut

    Local component easing function. This can be a function that return an integer or a string specifying a name of globally registered easing during installation.

  • tick function | required

    A function handler used to do animation. There are two parameters passed to this function, first is value which indicates current value between start to end. Each value is updated within 16ms through requestAnimationFrame. And the second parameter is event handler which passed by DOM addEventListener and can be used to do, i.e e.preventDefault() (to complement the lack of modifier for Vue 2.x).

  • done function

    A function handler that fired when tweening has reached the end value. Parameters passed are all the same as tick handler.

Consider to consult to jaxgeller/tweezer.js directly for more information and real example.

Example

<template>
  <div v-tween:click.capture="myTweening">
    <span :style="style"></span>
  </div>
</template>

<script>
export default {
  data () {
    return {
      style: {
        position: 'absolute',
        left: ''
      }
    }
  },
  methods () {
    myTweening () {
      return {
        start: 0,
        end: 1000,
        duration: 1000,
        tick (v, e) {
          e.preventDefault()
          this.style.left = `${v / 10}px`,
          this.style.opacity = `${(v / -1000) + 1}`
        },
        done (v, e) {
          this.style.opacity = '0'
        }
      }
    }
  }
}
</script>

License

MIT License

Copyright (c) 2016 Cahyadi Nugraha

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

vue-tween's People

Contributors

chay22 avatar

Stargazers

Trush avatar Jesse Tolj avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.