我正在使用 FitText https://github.com/davatron5000/FitText.js来调整我在特定 DIV 中的某些文本的文本大小。事实上,这些 DIV 仅在需要时才创建到添加到页面的对象中。但是这样做 FitText 在页面加载时不会获得 DIV,因为实际上 DIV 不存在,因此不会调整文本大小。
这是我如何称呼 FitText:
<script type="text/javascript">
jQuery(document).ready(function($) {
jQuery(".cvd_right_master_item").fitText(2.8);
});
</script>
这是将 DIV 创建为对象的函数:
function makeCvdBubble(params)
{
var cvdIndexId = params.cvdIndexId;
var cvdTweetAuthor = params.cvdTweetAuthor;
var cvdAuthorName = params.cvdAuthorName;
var cvdTweetDescription = params.cvdTweetDescription;
objectreference = document.createElement('div');
objectreference.setAttribute('id', 'indexId-'+cvdIndexId.toString());
$(objectreference).html('\
<div class="cvd_right_master_item">\
<div class="cvd_right_tweet_margin_float">\
<img class="cvd_right_blue_bird" src="cross_video_day/images/cvd_blue_bird.png" /><span class="cvd_right_tweet_username">@UserName</span>\
<span class="cvd_right_tweet_author">User Name</span>\
<span class="cvd_right_tweet_text">Lorem ipsum dolor sit amet, consectetur adipiscing elit. Cras ut posuere justo, eget consequat tortor. In sollicitudin condimentum arcu sed.</span>\
</div>\
<div class="clear_both"></div>\
<span class="cvd_right_white_arrow"></span>\
</div>\
');
if (cvdTweetAuthor) $(objectreference).find('.cvd_right_tweet_username').html(cvdTweetAuthor);
if (cvdAuthorName) $(objectreference).find('.cvd_right_tweet_author').html(cvdTweetAuthor);
if (cvdTweetDescription) $(objectreference).find('.cvd_right_tweet_text').html(cvdTweetDescription);
return (objectreference) //objectreference is the reference of the just created tweet
}
现在如何在创建对象时让 FitText 调整文本大小?谢谢!