1
0
Fork 0

Prevent layout thrashing by scroll height

This commit is contained in:
Jeroen Hermans 2020-11-15 22:03:39 +01:00
parent 3d701edc71
commit 957f928c70
1 changed files with 9 additions and 2 deletions

View File

@ -16,7 +16,7 @@ export default class Print {
* Configures the presentation for printing to a static
* PDF.
*/
setupPDF() {
async setupPDF() {
let config = this.Reveal.getConfig();
@ -48,6 +48,13 @@ export default class Print {
// Compute slide numbers now, before we start duplicating slides
let doingSlideNumbers = config.slideNumber && /all|print/i.test( config.showSlideNumber );
// Batch scrollHeight access to prevent layout thrashing
await new Promise(requestAnimationFrame);
const slideScrollHeights = []
slides.forEach( function( slide ) {
slideScrollHeights.push( slide.scrollHeight );
});
// Slide and slide background layout
slides.forEach( function( slide, index ) {
@ -58,7 +65,7 @@ export default class Print {
let left = ( pageWidth - slideWidth ) / 2,
top = ( pageHeight - slideHeight ) / 2;
let contentHeight = slide.scrollHeight;
const contentHeight = slideScrollHeights[ index ];
let numberOfPages = Math.max( Math.ceil( contentHeight / pageHeight ), 1 );
// Adhere to configured pages per slide limit