小编典典

HTML书状分页

html

如何将HTML文件的内容分成屏幕大小的块,以在WebKit浏览器中“分页”?

每个“页面”应显示完整数量的文本。这意味着不得在屏幕的顶部或底部边界将文本行切成两半。

编辑

该问题最初被标记为“ Android”,因为我的目的是构建Android
ePub阅读器。但是,看来该解决方案只能用JavaScript和CSS来实现,因此我扩大了问题的范围,使其与平台无关。


阅读 513

收藏
2020-05-10

共1个答案

小编典典

在Dan的答案基础上,是我对这个问题的解决方案,直到现在我一直在为此奋斗。(此JS可在iOS
Webkit上运行,不保证适用于android,但请告诉我结果)

var desiredHeight;
var desiredWidth;
var bodyID = document.getElementsByTagName('body')[0];
totalHeight = bodyID.offsetHeight;
pageCount = Math.floor(totalHeight/desiredHeight) + 1;
bodyID.style.padding = 10; //(optional) prevents clipped letters around the edges
bodyID.style.width = desiredWidth * pageCount;
bodyID.style.height = desiredHeight;
bodyID.style.WebkitColumnCount = pageCount;

希望这可以帮助…

2020-05-10