GithubHelp home page GithubHelp logo

web-animation-technologies's Introduction

Web animation tecnhologies

  • Native Animation

    • CSS
      • transform and opacity
      • Animation hooks as onAnimationEnd
      • Beyond chaining three animations in a row, move to JavaScript.
    • requestAnimationFrame
      • Native method on the window object in JavaScript
      • It figures out what the appropriate frame rate is for your animation
    • Canvas
      • It offers a visual space scripting, in which you can create complex drawings and interaction
      • Canvas is really nice with interaction
      • It’s difficult to make accessible
      • Unintuitive to make responsive
    • WebGL
      • Amazing visual effects
      • Hardware-accelerated
      • Tougher to learn than the other native animations
      • Hard to make responsive
  • External Libraries

    • GreenSock (GSAP)
      • Good performance
      • You have to pay for licensing if you're re-selling your product to multiple users
    • Three.js

Courses

GSAP 3

Project Vue and GSAP 3

  • Demo

  • Create Vue Project

    vue create vue-gsap-3
    
    • Manually select features: Babel, router, Linter
  • Run project

    cd vue-gsap-3
    npm run server
    
  • Simplify App.js

  • Change Home.vue to have this code:

    <template>
        <div ref="box" class="box"></div>
    </template>
    
    <style>
    .box {
        height: 60px;
        width: 60px;
        background: red;
    }
    </style>
    
  • Install GSAP:

    npm install gsap
    
  • Import gsap:

    <template>
        <div class="box"></div>
    </template>
    
    <script>
    /* eslint-disable new-cap */
    import gsap from 'gsap'
    export default {
        mounted () {
            const timeline = new gsap.timeline()
    
            timeline.to('.box', {
                duration: 2,
                x: 200,
                rotation: 90,
                backgroundColor: '#560563',
                ease: 'back'
            })
        }
    }
    </script>
    
    <style>
    .box {
        height: 60px;
        width: 60px;
        background: red;
    }
    </style>
    
  • The timeline instance exposes a to method, with which we pass 2 arguments:

    • Arg 1: The element to animate
    • Arg 2: An object describing the animation to perform
  • The html when you inspect the element is:

    <div class="box" style="background-color: rgb(86, 5, 99); transform: translate(200px, 0px) rotate(90deg);"></div>
    
  • Complete example in Home.vue

  • Greensock Ease visualizer: https://greensock.com/docs/v3/Eases

  • Deploy project:

    • Create file vue.config.js in root Vue project:

      module.exports = {
          publicPath: process.env.NODE_ENV === 'production' ? '/web-animation-technologies/gsap/vue-gsap-3/dist/' : '/'
      }
      
    • Generate dist files:

      npm run build
      
    • Add dist files to git (remove dist/ from .gitignore) and push to master

    • Enable GitHub Pages in settings

    • Project deployed in https://cristinafsanz.github.io/web-animation-technologies/gsap/vue-gsap-3/dist/#/

Project Vue and WinWheel (internally GSAP)

Timeline

Explanation in https://css-tricks.com/how-to-animate-on-the-web-with-greensock/.

To avoid having a delay until the second animation, like this:

gsap.to('.ball', {
  duration: 1.5,
  x: 200,
  scale: 2,
  ease: 'bounce'
})

gsap.to('.ball', {
  duration: 1.5,
  delay: 1.5,
  x: 0,
  scale: 1,
  ease: 'back.inOut(3)'
})

We using timeline:

gsap
  .timeline()
  .to(‘.ball’, {
    duration: 1.5,
    x: 200,
    scale: 2,
    ease: "bounce"
  })
  .to(‘.ball’, {
    duration: 1.5,
    x: 0,
    scale: 1,
    ease: "back.inOut(3)"
  });

This instantiates a timeline and then chains the two animations off of it.

Or with a default value for duration:

gsap
  .timeline({
    defaults: {
      duration: 1.5
    }
  })
  .to('.ball', {
    x: 200,
    scale: 2,
    ease: "bounce"
  })
  .to('.ball', {
    x: 0,
    scale: 1,
    ease: "back.inOut(3)"
  });
  • For loops, use repeat: -1:
gsap
  .timeline({
    repeat: -1,
    defaults: {
      duration: 1.5
    }
  })
  .to('.ball', {
    x: 200,
    scale: 2,
    ease: "bounce"
  })
  .to('.ball', {
    x: 0,
    scale: 1,
    ease: "back.inOut(3)"
  })
  .to('.ball', {
    x: -200,
    scale: 2,
    ease: "bounce"
  })
  .to('.ball', {
    x: 0,
    scale: 1,
    ease: "back.inOut(3)"
  });

Cool examples with GSAP

Click on the bell:

To better understand it, I created first a project with a previous example in gsap/css-tricks-article/label, downloading the gsap.min.js.

Labels (like start in the example) make sure things fire off at a particular point in time in the playhead of the animation. We can even increment and decrement from the label. I actually do this a lot in my animations. It looks like this: start+=0.25.

gsap
    .timeline({
        defaults: {
            duration: 1.5
        }
    })
    .add('start')
    .to('.ball', {
        x: 300,
        scale: 2,
        ease: "bounce"
    }, 'start')
    .to('.ball2', {
        x: 300,
        scale: 2,
        ease: "bounce"
    }, 'start+=0.25')
    .to('.ball3', {
        x: 300,
        scale: 2,
        ease: "bounce"
    }, 'start+=0.5')

web-animation-technologies's People

Contributors

cristinafsanz avatar

Watchers

James Cloos avatar  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.