Git Product home page Git Product logo

animatetext.js's Introduction

animateText

animateText is a vanilla function to animate every single character of a text sequentially.

Inspired by the text effects introduced in the Once Upon a Time in Hollywood Mag.

How to use

Setup

It's really simple. Add the script tag on your HTML.

<script src="https://cdn.jsdelivr.net/gh/happycrappie/animateText/dist/animate-text.umd.js"></script>

Then create a @keyframe in CSS—that will be your animation. Eg:

@keyframes fadeIn {
  from {
    transform: translateY(10px);
    opacity: 0;
  }

  to {
    transform: translateY(0px);
    opacity: 1;
  }
}

This keyframe will move the character up and slowly make it visible.

Animate the text

Then select trigger the animation on the element you want to animate.

animateText('.el')

Replace .el with the element you want to animate.

Customisation

You can customise the animation by declaring a few rules, such as:

  • Name: The name of the animation (keyframe).
  • Duration: Total time for the animation to start and finish playing.
  • Count: How many times the animation should play
  • Fill: What should happen with the animation after it ends.
  • Timing: The easing function.
  • Delay: How long it takes for the first animation to begin
  • Additional Delay: How much time will the next element wait to start animating.

You can customize the animation by passing the attribute values as an object in the second parameter:

// Change the Duration
animateText('#id', {duration: 2000});

// Set the name of the keyframe
animateText('#id', {name: 'moveUp'});

// Change multiple attributes
animateText('#id', {
  duration: 1000,
  delay: 200
})

Name

{String}

Define the name of the keyframe. Default: name: "fadeIn"

animateText('el', {name: 'animationName'})

If your keyframe isn't name "fadeIn", you should declare the name.

Duration

{Number}

Define how long the animation will take, from start to finish, in MILISECONDS. Default duration: 3000

animateText('el', {duration: 3000})

Count

{Number}

Define how many times the animation will run. Default count: 1

animateText('el', {count: 1})

Fill

{String}

Defines the animation fill mode. Default fill: "forwards"

animateText('el', {fill: "forwards"})

Timing

{String}

Defines the animation timing easing. Default timing: "cubic-bezier(0.215, 0.61, 0.355, 1)"

animateText('el', {timing: "cubic-bezier(0.215, 0.61, 0.355, 1)"})

Delay

{Number}

Defines the animation delay. Default delay: 0"

animateText('el', {delay: 0"})

Additional Delay

{Number}

Defines the amount of delay to stack up on the next characters. Default additionalDelay: 0"

animateText('el', {additionalDelay: 0"})

You can also pass it as a JSON

var attributes = {
  name: "animationName",
  delay: 500,
  additionalDelay: 90
}

animateText('el', attributes);

Author

Eryc da Silva

Contributor

Lucas Leandro

License

MIT

Copyright (c) 2019-present, Eryc da Silva.

animatetext.js's People

Contributors

0x00memex avatar lucasleandro1204 avatar dependabot[bot] 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.