javascript で TweenMax を使用して div の文字列文字をトゥイーンする方法:
h
he
hel
hell
hello
TweenMax にはそのための TextPlugin があり、非常に簡単です。
TweenMax.to(element, 2, {text:"hello"});
これにより、要素内のテキストが「hello」にトゥイーンされます。特定の時間などにトゥイーンまたは seek() を reverse() することもできます。ドキュメントはこちら: http://api.greensock.com/js/com/greensock/plugins/TextPlugin.html
TextPlugin を必ずロードしてください。そうしないと機能しません。
ハッピートゥイーン!
function TweenDivText(element, str) {
var string = { counter: 0, val: str };
TweenMax.to(string, string.val.length * 0.05, {
counter: string.val.length, onUpdate: function () {
element.text(string.val.substring(0, Math.ceil(string.counter)));
},
ease: Linear.easeNone
});
}
要素はjquery要素
です0.05を変更することで書き込み時間を変更できます。