別の に配置する必要がある 2500 語の文字列がありますDIV
。関数を使用してtext = text.split(' ')
各単語を取得し、よりも高くなるDIVs
まで入力してから、次の に進みます。DIV.scrollHeight
DIV.offsetHeight
DIV
私が遭遇した問題は、2500 語の文字列の HTML タグが完全に台無しになっていることです。<b>
タグを閉じるべきではない場所で閉じ、本来あるべき場所を表示せず、このタグの一部を</b>
表示せず、タグを閉じません。などを<font
表示しない</font>
理由はありますか?
どうもありがとう!
編集: 要求どおり、ここに jQuery コード全体があります。間違いがある場合は事前にお許しください:)
function addText(texte)
{
// var texte = texte.replace('<', '<');
// var texte = texte.replace('>', '>');
var container = $('DIV[id^=apDiv]').find('DIV#bloc_prim');
console.log('NOMBRE DE CONTAINER : '+container.length);
var length = texte.length;
console.log('LONGUEUR DU TEXTE '+length+' caractères');
// container.html(texte);
var hauteurDiv = container.prop('offsetHeight');
var hauteurContent = container.prop('scrollHeight');
length = Math.floor((length * hauteurDiv)/hauteurContent);
console.log(hauteurContent);
// container.html(texte.substring(0, length));
var hauteurRestante = hauteurContent - hauteurDiv;
console.log(hauteurRestante);
var TABLEAU = texte.split(' ');
// var TABLEAU = texte.match(/<\s*(\w+\b)(?:(?!<\s*\/\s*\1\b)[\s\S])*<\s*\/\s*\1\s*>|\S+/g);
console.log('LONGUEUR TABLEAU : '+TABLEAU.length+' occurences');
// console.log(TABLEAU[4]);
i = 0;
hauteurTotale = container.prop('scrollHeight');
console.log(container.prop('offsetHeight'));
console.log(hauteurTotale);
while(i < TABLEAU.length)
{
while(hauteurTotale <= container.prop('offsetHeight'))
{
container.append(TABLEAU[i]+' ');
i++;
hauteurTotale = container.prop('scrollHeight');
console.log(i+':'+hauteurTotale+' --- '+container.prop('offsetHeight'));
}
if(i < TABLEAU.length)
{
var clone = container.parent('DIV[id^=apDiv]').clone(true); // On copie la DIV
$('BODY').append(clone); // On colle la partie copiée
clone.find('DIV#bloc_prim').empty();
}
var hauteurTotale = clone.find('DIV#bloc_prim').prop('scrollHeight');
console.log(hauteurTotale);
while(hauteurTotale <= clone.find('DIV#bloc_prim').prop('offsetHeight'))
{
if(i < TABLEAU.length)
{
clone.find('DIV#bloc_prim').append(TABLEAU[i]+' ');
i++;
hauteurTotale = clone.find('DIV#bloc_prim').prop('scrollHeight');
console.log(i+':'+hauteurTotale+' --- '+container.prop('offsetHeight'));
}
else
{
break;
}
}
}
console.log(i+'->'+TABLEAU.length);