HTML book-like pagination

后端 未结 10 1403
清歌不尽
清歌不尽 2020-11-27 09:29

How can I split the content of a HTML file in screen-sized chunks to \"paginate\" it in a WebKit browser?

Each \"page\" should show a complete amount of text. This

10条回答
  •  夕颜
    夕颜 (楼主)
    2020-11-27 10:11

    Building on Dan's answer here is my solution for this problem, with which I was struggling myself until just now. (this JS works on iOS Webkit, no guarantees for android, but please let me know the results)

    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;
    

    Hope this helps...

提交回复
热议问题