ジェイクエリーの1文字ずつのテキストアニメーションで複数行対応する方法で困っています
splitで1文字ずつ配列にいれてforeachで配列をspanでくくりアニメーションさせているのですが
brタグなども1文字ずつ格納されてしまうためbrタグは1文字で格納されないようにしたいのですが方法がわかりません
欲を言えばbrタグのみではなくhtmlタグは1文字で配列に格納されずにしたいです。
また、foreachで回してspanを取り付ける方法ではなくて
htmlにspanを書く方法だと簡単に実装できるかと思うのですが毎回1文字ずつspanで囲むのが大変になるので、できればしたくありません。
初めて投稿するため勝手がわかりませんが、今現在このような感じです。
どなたかいいやり方ご教授いただけると助かります。
html
1<p class="text_animate">te<br>st</p>
scss
1 2.text_animate{ 3 span{ 4 transition: 1s; 5 opacity: 0; 6 &.text_animate_on{ 7 transition: 1s; 8 opacity: 1; 9 10 } 11 } 12 &.text_animate_rotate span{ 13 transform: rotate(-45deg); 14 display: inline-block; 15 &.text_animate_rotate_on{ 16 transform: rotate(0deg); 17 } 18 } 19 &.text_animate_size span{ 20 font-size: 22px; 21 &.text_animate_size_on{ 22 font-size: 10px; 23 } 24 } 25}
javascript
1$(function(){ 2 var text=$(".text_animate").html(); 3 /*var html_tags = /</?[^>]+>/; 4 var text_split=text.split(html_tags);*/ 5 var text_split=text.split(""); 6 $(".text_animate").html(""); 7 function animate(){ 8 text_split.forEach(function(val){ 9 /*console.log(val);*/ 10 11 12 $(".text_animate").append("<span>"+val+"</span>"); 13 14 }); 15 16 } 17 animate(); 18 $(window).load(function(){ 19 $(".text_animate span").each(function(index){ 20 $(this).css({transitionDelay:index * 0.6 +"s"}).addClass("text_animate_on"); 21 }); 22 }); 23});

回答3件
あなたの回答
tips
プレビュー