LoginSignup
30
33

More than 5 years have passed since last update.

テキストを1文字ずつフェードインさせる方法

Last updated at Posted at 2017-11-07

デモ

20171107150838.gif

コード

HTML

<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.2.1/jquery.min.js"></script>
<h1 id="title">Sample Text</h1>

CSS

#title {
    color: #fff;
    font-size: 48px;
}

JS

$(function() {
    var $allMsg = $('#title');
    var $wordList = $('#title').html().split("");
    $('#title').html("");
    $.each($wordList, function(idx, elem) {
        var newEL = $("<span/>").text(elem).css({ opacity: 0 });
        newEL.appendTo($allMsg);
        newEL.delay(idx * 70);
        newEL.animate({ opacity: 1 }, 1100);
    });
});

参考

Fade in letter by letter with JQuery - Stack Overflow

30
33
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
30
33