これらの文字列は長い段落である可能性があるため、文字列全体をスペース区切り文字で分割するのが最善かどうかはわかりません。たとえば、最初の10語を取得して、それらをスパンでラップしようとしています。
'<span class="easing">' + string + '</span>'
次に、元の分割の後半でそれを再結合します。これを行うための超効率的な方法に関する提案はありますか?一度にページの最大3つの段落に影響します。
編集済み
ここにキッカーがあります—分割は9番目の単語の後で、または最初の文の終わりで発生する必要があります(その文が9単語未満の場合)。
例
var origString = 'Coming into the world on Elvis’ birthday with a doctor named Presley seemed fortuitous until, wielding the silvery smooth scalpel in his aged unsteady hand, the doctor sliced through the walls of my mother’s uterus and into my unborn skin. Inside the warm soothing waters of my mother’s womb, inside the silent weightlessness, I was safe. Then the prick of cold steel marked the first in a series of rude awakenings. I was scarred for life even before birth.';
var newString = '<span="easing">Coming into the world on Elvis’ birthday with a doctor</span> named Presley seemed fortuitous until, wielding the silvery smooth scalpel in his aged unsteady hand, the doctor sliced through the walls of my mother’s uterus and into my unborn skin. Inside the warm soothing waters of my mother’s womb, inside the silent weightlessness, I was safe. Then the prick of cold steel marked the first in a series of rude awakenings. I was scarred for life even before birth.';
または、段落を開始する短い文で:
var origString = '“Is he okay? Tell me everything’s okay” she pleas, her desperate need to confirm my health competing with her own need for consolation.';
var newString = '<span class="easing">“Is he okay?</span> Tell me everything’s okay” she pleas, her desperate need to confirm my health competing with her own need for consolation.';