Problem:
How to display a HTML document in a WebKit browser in "pages" that are the size of the screen and contain complete lines of text, so that they can be read like a book?
Solution:
Using JavaScript and CSS:
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;
This solution involves setting the body element's dimensions and enabling column-based layout using "WebkitColumnCount" to create multiple pages with the desired number of columns.
By calculating the total height of the body and dividing it by the desired page height, the number of pages is determined. Then, the body is given a specific width (determined by the desired page width) multiplied by the number of pages, and a height equal to the page height. Finally, the column count is set to the same number of pages.
This approach ensures that the content is divided into screen-sized chunks, with no lines of text being cut off within screen boundaries. It also allows for multiple pages to be created seamlessly within a single HTML document, providing a book-like pagination experience for WebKit-based browsers.
The above is the detailed content of How to Implement Two-Dimensional Paginated HTML Documents for EPub Readers Using JavaScript and CSS?. For more information, please follow other related articles on the PHP Chinese website!