浏览代码

add support for keyboard navigation in scroll view #3515

Hakim El Hattab 1 年之前
父节点
当前提交
5d131cea20
共有 6 个文件被更改,包括 40 次插入4 次删除
  1. 0 0
      dist/reveal.esm.js
  2. 0 0
      dist/reveal.esm.js.map
  3. 0 0
      dist/reveal.js
  4. 0 0
      dist/reveal.js.map
  5. 22 4
      js/controllers/scrollview.js
  6. 18 0
      js/reveal.js

文件差异内容过多而无法显示
+ 0 - 0
dist/reveal.esm.js


文件差异内容过多而无法显示
+ 0 - 0
dist/reveal.esm.js.map


文件差异内容过多而无法显示
+ 0 - 0
dist/reveal.js


文件差异内容过多而无法显示
+ 0 - 0
dist/reveal.js.map


+ 22 - 4
js/controllers/scrollview.js

@@ -277,7 +277,7 @@ export default class ScrollView {
 		const pageHeight = useCompactLayout ? compactHeight : viewportHeight;
 		const pageHeight = useCompactLayout ? compactHeight : viewportHeight;
 
 
 		// The height that needs to be scrolled between scroll triggers
 		// The height that needs to be scrolled between scroll triggers
-		const scrollTriggerHeight = useCompactLayout ? compactHeight : viewportHeight;
+		this.scrollTriggerHeight = useCompactLayout ? compactHeight : viewportHeight;
 
 
 		this.viewportElement.style.setProperty( '--page-height', pageHeight + 'px' );
 		this.viewportElement.style.setProperty( '--page-height', pageHeight + 'px' );
 		this.viewportElement.style.scrollSnapType = typeof config.scrollSnap === 'string' ? `y ${config.scrollSnap}` : '';
 		this.viewportElement.style.scrollSnapType = typeof config.scrollSnap === 'string' ? `y ${config.scrollSnap}` : '';
@@ -333,12 +333,12 @@ export default class ScrollView {
 			for( let i = 0; i < totalScrollTriggerCount + 1; i++ ) {
 			for( let i = 0; i < totalScrollTriggerCount + 1; i++ ) {
 				const triggerStick = document.createElement( 'div' );
 				const triggerStick = document.createElement( 'div' );
 				triggerStick.className = 'scroll-snap-point';
 				triggerStick.className = 'scroll-snap-point';
-				triggerStick.style.height = scrollTriggerHeight + 'px';
+				triggerStick.style.height = this.scrollTriggerHeight + 'px';
 				triggerStick.style.scrollSnapAlign = useCompactLayout ? 'center' : 'start';
 				triggerStick.style.scrollSnapAlign = useCompactLayout ? 'center' : 'start';
 				page.pageElement.appendChild( triggerStick );
 				page.pageElement.appendChild( triggerStick );
 
 
 				if( i === 0 ) {
 				if( i === 0 ) {
-					triggerStick.style.marginTop = -scrollTriggerHeight + 'px';
+					triggerStick.style.marginTop = -this.scrollTriggerHeight + 'px';
 				}
 				}
 			}
 			}
 
 
@@ -355,7 +355,7 @@ export default class ScrollView {
 			}
 			}
 
 
 			// Add scroll padding based on how many scroll triggers we have
 			// Add scroll padding based on how many scroll triggers we have
-			page.scrollPadding = scrollTriggerHeight * totalScrollTriggerCount;
+			page.scrollPadding = this.scrollTriggerHeight * totalScrollTriggerCount;
 
 
 			// The total height including scrollable space
 			// The total height including scrollable space
 			page.totalHeight = page.pageHeight + page.scrollPadding;
 			page.totalHeight = page.pageHeight + page.scrollPadding;
@@ -699,6 +699,24 @@ export default class ScrollView {
 
 
 	}
 	}
 
 
+	/**
+	 * Scroll to the previous page.
+	 */
+	prev() {
+
+		this.viewportElement.scrollTop -= this.scrollTriggerHeight;
+
+	}
+
+	/**
+	 * Scroll to the next page.
+	 */
+	next() {
+
+		this.viewportElement.scrollTop += this.scrollTriggerHeight;
+
+	}
+
 	/**
 	/**
 	 * Scrolls the given slide element into view.
 	 * Scrolls the given slide element into view.
 	 *
 	 *

+ 18 - 0
js/reveal.js

@@ -2499,6 +2499,9 @@ export default function( revealElement, options ) {
 
 
 		navigationHistory.hasNavigatedHorizontally = true;
 		navigationHistory.hasNavigatedHorizontally = true;
 
 
+		// Scroll view navigation is handled independently
+		if( scrollView.isActive() ) return scrollView.prev();
+
 		// Reverse for RTL
 		// Reverse for RTL
 		if( config.rtl ) {
 		if( config.rtl ) {
 			if( ( overview.isActive() || skipFragments || fragments.next() === false ) && availableRoutes().left ) {
 			if( ( overview.isActive() || skipFragments || fragments.next() === false ) && availableRoutes().left ) {
@@ -2516,6 +2519,9 @@ export default function( revealElement, options ) {
 
 
 		navigationHistory.hasNavigatedHorizontally = true;
 		navigationHistory.hasNavigatedHorizontally = true;
 
 
+		// Scroll view navigation is handled independently
+		if( scrollView.isActive() ) return scrollView.next();
+
 		// Reverse for RTL
 		// Reverse for RTL
 		if( config.rtl ) {
 		if( config.rtl ) {
 			if( ( overview.isActive() || skipFragments || fragments.prev() === false ) && availableRoutes().right ) {
 			if( ( overview.isActive() || skipFragments || fragments.prev() === false ) && availableRoutes().right ) {
@@ -2531,6 +2537,9 @@ export default function( revealElement, options ) {
 
 
 	function navigateUp({skipFragments=false}={}) {
 	function navigateUp({skipFragments=false}={}) {
 
 
+		// Scroll view navigation is handled independently
+		if( scrollView.isActive() ) return scrollView.prev();
+
 		// Prioritize hiding fragments
 		// Prioritize hiding fragments
 		if( ( overview.isActive() || skipFragments || fragments.prev() === false ) && availableRoutes().up ) {
 		if( ( overview.isActive() || skipFragments || fragments.prev() === false ) && availableRoutes().up ) {
 			slide( indexh, indexv - 1 );
 			slide( indexh, indexv - 1 );
@@ -2542,6 +2551,9 @@ export default function( revealElement, options ) {
 
 
 		navigationHistory.hasNavigatedVertically = true;
 		navigationHistory.hasNavigatedVertically = true;
 
 
+		// Scroll view navigation is handled independently
+		if( scrollView.isActive() ) return scrollView.next();
+
 		// Prioritize revealing fragments
 		// Prioritize revealing fragments
 		if( ( overview.isActive() || skipFragments || fragments.next() === false ) && availableRoutes().down ) {
 		if( ( overview.isActive() || skipFragments || fragments.next() === false ) && availableRoutes().down ) {
 			slide( indexh, indexv + 1 );
 			slide( indexh, indexv + 1 );
@@ -2557,6 +2569,9 @@ export default function( revealElement, options ) {
 	 */
 	 */
 	function navigatePrev({skipFragments=false}={}) {
 	function navigatePrev({skipFragments=false}={}) {
 
 
+		// Scroll view navigation is handled independently
+		if( scrollView.isActive() ) return scrollView.prev();
+
 		// Prioritize revealing fragments
 		// Prioritize revealing fragments
 		if( skipFragments || fragments.prev() === false ) {
 		if( skipFragments || fragments.prev() === false ) {
 			if( availableRoutes().up ) {
 			if( availableRoutes().up ) {
@@ -2596,6 +2611,9 @@ export default function( revealElement, options ) {
 		navigationHistory.hasNavigatedHorizontally = true;
 		navigationHistory.hasNavigatedHorizontally = true;
 		navigationHistory.hasNavigatedVertically = true;
 		navigationHistory.hasNavigatedVertically = true;
 
 
+		// Scroll view navigation is handled independently
+		if( scrollView.isActive() ) return scrollView.next();
+
 		// Prioritize revealing fragments
 		// Prioritize revealing fragments
 		if( skipFragments || fragments.next() === false ) {
 		if( skipFragments || fragments.next() === false ) {
 
 

部分文件因为文件数量过多而无法显示