長いブロックのテキストをページに分割するページ分割スクリプトを作成しました。最初に、テキストは#pageというIDでdivにロードされます。次に、スクリプトは#pageの高さを測定し、div .detailsholderでdivに収まるように分割するページ数を計算します。MacとPCでJavascriptの動作が異なりますか?
div .detailsholderがクリアされ、適切な数のページ区切りが内部に追加されます。 (それぞれ実際には#pageの本文全体がありますが、上の余白は設定されており、高さは固定されており、オーバーフローは隠しに設定されているため、適切な額だけが表示されます)。
そして、これを除いて:MacのSafariとFirefoxは完全に機能しますが、WindowsのIEとFirefoxは余分なページを追加します。上の括弧で説明したように、ページが作成される方法のため、最後のページは空白になります。テキストがページ「ウィンドウ」に表示されるまでには余りに上に移動します。
ここにコードがあります。私はjQueryを使用しています。
var descHeight = $('#page').outerHeight();
if (descHeight > 250) {
var numberOfPages = Math.round(descHeight/210)+1; //Figure out how many pages
var artistText = $('#page').html(); //Grab the text into a variable
$('.detailsholder').empty(); //Empty the container so we can fill
//it with pages
for (i=0;i<=numberOfPages-1;i++) { //Each page has the entire text
//content, but is shifted up and
var shiftUp = 0-(210 * i); //cut off at the bottom.
$('.detailsholder').append('<div id="page' + (i+1) + '" class="page" style="height:225px;"><div style="border:dotted 1px red;margin-top:' + shiftUp + 'px"' + artistText + '</div>');
}
}
ありがとう!
ありがとうございます! Math.floorに変えてトリックをやった! – jeffedsell