【发布时间】:2010-10-26 15:16:32
【问题描述】:
我创建了一个分页脚本,它需要很长的文本块并将其分成页面。首先,将文本加载到 id 为 #page 的 div 中。然后脚本测量#page 的高度并计算它应该分成多少页以适应div 类.detailsholder。
div .detailsholder 被清空,并在里面添加适当数量的页面 div。 (每一个其实里面都有#page的整个文本,但是上边距设置为负数,高度固定,溢出设置为隐藏,所以只出现适量。)
而且它运行良好,除了这一点:Mac 上的 Safari 和 Firefox 运行良好,而 Windows 上的 IE 和 Firefox 添加了一个额外的页面。由于页面的创建方式(如上面括号中所述),最后一页显示为空白 - 文本向上移动太远而无法显示在页面 window 中。
这是代码。如您所见,我正在使用 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>');
}
}
谢谢!
【问题讨论】:
标签: javascript css windows macos browser