Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 794243
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 14, 20262026-05-14T22:17:03+00:00 2026-05-14T22:17:03+00:00

How would I animate individual characters of text on a page in HTML5. Like

  • 0

How would I animate individual characters of text on a page in HTML5. Like this example in flash.
http://www.greensock.com/splittextfield/

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-14T22:17:03+00:00Added an answer on May 14, 2026 at 10:17 pm

    You’d have to wrap each character in a <span> then move that span using CSS position/top/left.

    You couldn’t completely reproduce what the Flash example did, because that example uses a blur effect. CSS can’t do that; SVG could, and IE’s non-standard filter could, but that would mean a total code branch.

    You could change the size of each letter by setting the font-size, but to so the kind of shear/rotate effects the example does you’d have to use a CSS transform. This isn’t standardised yet and there are holes in browser support.

    Here’s a proof-of-concept I just hacked up mainly for Firefox (sorry for the code length):

    <p id="effect">I've got a lovely bunch of coconuts.</p>
    <button id="animate">Animate</button>
    
    
    // Add ECMA262-5 method binding if not supported natively
    //
    if (!('bind' in Function.prototype)) {
        Function.prototype.bind= function(owner) {
            var that= this;
            if (arguments.length<=1) {
                return function() {
                    return that.apply(owner, arguments);
                };
            } else {
                var args= Array.prototype.slice.call(arguments, 1);
                return function() {
                    return that.apply(owner, arguments.length===0? args : args.concat(Array.prototype.slice.call(arguments)));
                };
            }
        };
    }
    
    // Lightweight class/instance system
    //
    Function.prototype.makeSubclass= function() {
        function Class() {
            if (!(this instanceof Class))
                throw 'Constructor function requires new operator';
            if ('_init' in this)
                this._init.apply(this, arguments);
        }
        if (this!==Object) {
            Function.prototype.makeSubclass.nonconstructor.prototype= this.prototype;
            Class.prototype= new Function.prototype.makeSubclass.nonconstructor();
        }
        return Class;
    };
    Function.prototype.makeSubclass.nonconstructor= function() {};
    
    // Abstract base for animated linear sliding switch between 0 and 1
    //
    var Animation= Object.makeSubclass();
    Animation.prototype._init= function(period, initial) {
        this.period= period;
        this.interval= null;
        this.aim= initial || 0;
        this.t= 0;
    };
    Animation.prototype.set= function(aim) {
        if (aim===this.aim)
            return;
        this.aim= aim;
        var now= new Date().getTime();
        if (this.interval===null) {
            this.t= now;
            this.interval= window.setInterval(this.update.bind(this), 32);
        } else {
            this.t= now-this.t-this.period+now
            this.update();
        }
    };
    Animation.prototype.toggle= function() {
        this.set(this.aim===0? 1 : 0);
    };
    Animation.prototype.update= function() {
        var now= new Date().getTime();
        var x= Math.min((now-this.t)/this.period, 1);
        this.show(this.aim===0? 1-x : x);
        if (x===1) {
            window.clearInterval(this.interval);
            this.interval= null;
        }
    };
    Animation.prototype.show= function(d) {};
    
    // Animation that spins each character in a text node apart
    //
    var ExplodeAnimation= Animation.makeSubclass();
    ExplodeAnimation.prototype._init= function(node, period) {
        Animation.prototype._init.call(this, period, 0);
        this.spans= [];
    
        // Wrap each character in a <span>
        //
        for (var i= 0; i<node.data.length; i++) {
            var span= document.createElement('span');
            span.style.position= 'relative';
            span.appendChild(document.createTextNode(node.data.charAt(i)));
            node.parentNode.insertBefore(span, node);
            this.spans.push(span);
        }
    
        // Make up random positions and speeds for each character.
        // Possibly this should be re-randomised on each toggle?
        //
        this.randomness= [];
        for (var i= this.spans.length; i-->0;)
            this.randomness.push({
                dx: Math.random()*200-100, dy: Math.random()*200-150,
                sx: Math.random()*1.5, sy: Math.random()*1.5,
                dr: Math.random()*240-120, og: Math.random()+0.5
            });
    
        node.parentNode.removeChild(node);
    };
    ExplodeAnimation.prototype.show= function(d) {
        for (var i= this.spans.length; i-->0;) {
            var style= this.spans[i].style;
            var r= this.randomness[i];
    
            style.left= d*r.dx+'px';
            style.top= d*r.dy+'px';
            var transform= 'rotate('+Math.floor(d*r.dr)+'deg) scale('+(d*r.sx+1-d)+', '+(d*r.sy+1-d)+')';
            if ('transform' in style)
                style.transform= transform;
            else if ('MozTransform' in style)
                style.MozTransform= transform;
    
            var o= 1-Math.pow(d, r.og);
            if ('opacity' in style)
                style.opacity= o+'';
            else if ('filter' in style)
                style.filter= 'opacity(alpha='+Math.ceil(o*100)+')';
        }
    };
    
    
    var animation= new ExplodeAnimation(document.getElementById('effect').firstChild, 1000);
    document.getElementById('animate').onclick= animation.toggle.bind(animation);
    

    This could be improved by adding gravity and better 3D-space modelling of the currently-completely-random transforms, plus better browser support for the scale/rotation in browsers other than Firefox.

    (IE has its own non-standard CSS transform filters it might be possible to support; Webkit and Opera have webkitTransform and oTransform styles, but they refuse to transform relative-positioning inline spans, so you’d have to absolute-position each character, which would mean reading all their normal positions to use as baseline. I got bored at this point.)

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I would like to animate an html page with something like this: function showElements(a)
I'm not sure how this links are called something.com/#link I would like to animate
http://www.hotelterrajacksonhole.com I have searched, but haven't found any galleries that would animate the images
I would like to animate things in 3D space. I know this is possible
I would like to animate a graph that grows over time. This is what
I would like to animate a 40x20 block of characters that I am cout
I have a jQuery animation example here : http://jsfiddle.net/p7Eta/ I would like all the
I would like to animate movement on a SurfaceView . Ideally I would like
I would like to animate a ScatterView Control using Expression Blend However, it seems
I would like to animate a view along a path. While it moves from

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.