4
4

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

javascriptのsplitで1文字ずつ分割してアニメーションさせる

Last updated at Posted at 2014-01-15

“abcde”.split(‘’);の結果
スクリーンショット 2014-01-15 21.17.24.png

こんな感じの何かが出来るのではないかと。
2624d02542e1abea7634ede7034ea468.gif

文字がランダムで降ってくるとか出来そうですね。
※ つくれぽお待ちしております←

split.js


(function(){

    var text = 'Now Loading...';
        arrReceive = [];

    arrReceive = text.split('');

    console.dir(arrReceive);

    var arrLength = arrReceive.length;

    for(var i=0; i<arrLength; i++) {
        arrReceive[i] = '<span class="str-animate">'+ arrReceive[i] +'</span>';
    }


    var htmlText = arrReceive.join("");

    // アニメーション処理
    $('body').append(htmlText);


    var loop = function() {
        $('.str-animate').each(function(_idx) {
            var that = $(this);

            setTimeout(function() {
                that
                    .css({
                        position: "relative"
                    })
                    .animate({
                        top: -30
                    }, 300, function() {
                        that.animate({
                            top: 0
                        }, 300);
                    });
            }, 60*_idx);
        });
    };


    setInterval(loop, 2000);

})();


// ----------------- 参考URL
・ Myth Busting: CSS Animations vs. JavaScript
http://css-tricks.com/myth-busting-css-animations-vs-javascript/
・ CodePen Source
http://codepen.io/GreenSock/pen/AwCKp

4
4
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
4
4

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?