Skip to content

Commit

Permalink
fix scroll snapping in reader mode compact layout
Browse files Browse the repository at this point in the history
  • Loading branch information
hakimel committed Oct 25, 2023
1 parent ff252c9 commit e46bad3
Show file tree
Hide file tree
Showing 7 changed files with 10 additions and 13 deletions.
4 changes: 0 additions & 4 deletions css/reveal.scss
Original file line number Diff line number Diff line change
Expand Up @@ -1946,10 +1946,6 @@ $notesWidthPercent: 25%;
overflow: hidden;
}

.reader-snap-point {
scroll-snap-align: start;
}

.reader-page section {
visibility: visible !important;
display: block !important;
Expand Down
2 changes: 1 addition & 1 deletion dist/reveal.css

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion dist/reveal.esm.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion dist/reveal.esm.js.map

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion dist/reveal.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion dist/reveal.js.map

Large diffs are not rendered by default.

9 changes: 5 additions & 4 deletions js/controllers/reader.js
Original file line number Diff line number Diff line change
Expand Up @@ -270,14 +270,14 @@ export default class Reader {

const slideSize = this.Reveal.getComputedSlideSize( window.innerWidth, window.innerHeight );
const scale = this.Reveal.getScale();
const readerLayout = config.readerLayout;
const useCompactLayout = config.readerLayout === 'compact';

const viewportHeight = this.viewportElement.offsetHeight;
const compactHeight = slideSize.height * scale;
const pageHeight = readerLayout === 'full' ? viewportHeight : compactHeight;
const pageHeight = useCompactLayout ? compactHeight : viewportHeight;

// The height that needs to be scrolled between scroll triggers
const scrollTriggerHeight = viewportHeight;
const scrollTriggerHeight = useCompactLayout ? compactHeight : viewportHeight;

this.viewportElement.style.setProperty( '--page-height', pageHeight + 'px' );
this.viewportElement.style.scrollSnapType = typeof config.readerScrollSnap === 'string' ?
Expand Down Expand Up @@ -335,6 +335,7 @@ export default class Reader {
const triggerStick = document.createElement( 'div' );
triggerStick.className = 'reader-snap-point';
triggerStick.style.height = scrollTriggerHeight + 'px';
triggerStick.style.scrollSnapAlign = useCompactLayout ? 'center' : 'start';
page.pageElement.appendChild( triggerStick );

if( i === 0 ) {
Expand All @@ -345,7 +346,7 @@ export default class Reader {
// In the compact layout, only slides with scroll triggers cover the
// full viewport height. This helps avoid empty gaps before or after
// a sticky slide.
if( readerLayout === 'compact' && page.scrollTriggers.length > 0 ) {
if( useCompactLayout && page.scrollTriggers.length > 0 ) {
page.pageHeight = viewportHeight;
page.pageElement.style.setProperty( '--page-height', viewportHeight + 'px' );
}
Expand Down

0 comments on commit e46bad3

Please sign in to comment.