开发者

Preserve formatting of text using letterings.js

Is there a way to preserve formatting (e.g. bold, italic) of text when using the letterings.js plugin? I am using the "word" wrapping function (https://github.com/davatron5000/Lettering.js/wiki/Wrapping-words-with-lettering%28%27words%27%29) and it seems to destroy any formatting made of the text.

Here's an example:

<div class="text-block">This is a <i>se开发者_如何学JAVAntence</i> <b>with <i>formatting</i></b>.</div>

After using letterings.js, it turns into:

<div class="text-block">
   <span class="word1">This</span>
   <span class="word2">is</span>
   <span class="word3">a</span>
   <span class="word4">sentence</span>
   <span class="word5">with</span>
   <span class="word6">formatting.</span>
</div>

This is the function I'm using in jQuery:

$('.text-block').lettering('words');

I've found that I can preserve bold or italic (unfortunately not both) doing this:

$('.text-block b').lettering('words');

-OR-

$('.text-block i').lettering('words');

You can't use both ( i.e. $('.text-block b,.text-block i') ) at the same time.

If it's not possible with letterings.js, is there another plugin or method to wrap each word in spans but preserve the formatting?


If you change the method in line 15 from .text() to .html(), you can use

$('.text-block').lettering('words');

as is and it will not strip the tags.

Use this link to get the source:

https://gist.github.com/klatchbaldar/6956474

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜