Git Product home page Git Product logo

wobbletext's Introduction

Wobble Text โ€” the one and only library to animate wiggles into your text

Installation

Copy index.min.js into a file in your project and reference it in your HTML

Usage

WobbleText adds a WobbleText function to the global window object.

Call the wobble function like this:

WobbleText(element, {
    // options
})

Options

resolution

The amount of elements the text is split into. Higher resolution = worse performance. Lower resolution = worse appearance.

If you decrease the resolution, you may want to tweak some other options to get it to look more uniform.

Default is 20.

speed

What it says it is. If you have any ideas on how to better describe it, be sure to make a pull request.

Higher number = lower speed, lower number = higher speed.

Default is 30.

intensity

What the sine is multiplied by. Higher numbers make the elements skewed more.

Default is 10.

wobbliness

The speed of individual elements. Lower numbers make it look more like the text is just being skewed. Higher numbers make it look more wobbly.

Default is 1.

overlapProtection

A number in between 0 and 1. 1 makes the clip-path of the elements overlap each other more, therefore protecting them from having any gaps in between themselves.

Make sure to use the right overlap protection for your use case, as lower numbers give a more accurate simulation.

Default is 0.

direction

A string, either x or y. This really only changes the way it's skewed (skewX vs skewY). Default is x.

gradient

An object with 2 properties: from and to

These properties contain an array of numbers as HSL values.

Example:

gradient: {
    from: [270, 100, 60], // Purple
    to: [220, 100, 80]    // Light blue
}

This will make the text color a gradient from purple top to light blue bottom. It lerps between from and to for each individual element (higher resolution = more accuracy!)

How it works

  • The text is split into a number of <p> elements (determined by options.resolution)
  • Each element is then clip-pathed to a certain vertical/horizontal range. The percentage is determined by its index.
  • Their skewX/skewY transform property is updated each frame by this equation:
    • Math.sin((tick + delay * wobbliness) / (speed * resolution)) * intensity
    • Tick is the tick count (increased every frame, obviously)
    • Delay is the element's index multiplied by 100
    • Wobbliness, speed, resolution, and intensity can all be specified in options

Example

The example can be found either at example.html or this Codepen link.


Current Version: 0.2.0 (beta)

Author: PineappleRind

wobbletext's People

Contributors

pineapplerind 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.