Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add "touchY" plugin #753

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion build.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ files.push('src/plugins/autoplay/autoplay.js',
'src/plugins/stop/stop.js',
'src/plugins/substep/substep.js',
'src/plugins/touch/touch.js',
'src/plugins/touchY/touchY.js',
'src/plugins/toolbar/toolbar.js')
var output = files.map((f)=>{
return fs.readFileSync(f).toString();
Expand Down Expand Up @@ -71,4 +72,4 @@ html += '</body>\n</html>'

filename = path.resolve(__dirname, 'examples', 'index.html');
fs.writeFileSync(filename, html);
console.log(filename);
console.log(filename);
67 changes: 67 additions & 0 deletions src/plugins/touchY/touchY.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
/**
* Support for swipe and tap on touch devices
*
* This plugin implements navigation for plugin devices, via swiping up/down,
* or tapping on the up/down edges of the screen.
*
* This is a modified "touch" plugin for impress.js, 2020: Arsenii Lyzenko
* (@pticagovorun)
*
*
* MIT License
*/
/* global document, window */
( function( document, window ) {
"use strict";

// Touch handler to detect swiping up and down based on window size.
// If the difference in Y change is bigger than 1/20 of the screen height,
// we simply call an appropriate API function to complete the transition.
var startY = 0;
var lastY = 0;
var lastDY = 0;
var threshold = window.innerHeight / 20;

document.addEventListener( "touchstart", function( event ) {
lastY = startY = event.touches[ 0 ].clientY;
} );

document.addEventListener( "touchmove", function( event ) {
var y = event.touches[ 0 ].clientY;
var diff = y - startY;

// To be used in touchend
lastDY = lastY - y;
lastY = y;

window.impress().swipe( diff / window.innerHeight );
} );

document.addEventListener( "touchend", function() {
var totalDiff = lastY - startY;
if ( Math.abs( totalDiff ) > window.innerHeight / 5 && ( totalDiff * lastDY ) <= 0 ) {
if ( totalDiff > window.innerHeight / 5 && lastDY <= 0 ) {
window.impress().prev();
} else if ( totalDiff < -window.innerHeight / 5 && lastDY >= 0 ) {
window.impress().next();
}
} else if ( Math.abs( lastDY ) > threshold ) {
if ( lastDY < -threshold ) {
window.impress().prev();
} else if ( lastDY > threshold ) {
window.impress().next();
}
} else {

// No movement - move (back) to the current slide
window.impress().goto( document.querySelector( "#impress .step.active" ) );
}
} );

document.addEventListener( "touchcancel", function() {

// Move (back) to the current slide
window.impress().goto( document.querySelector( "#impress .step.active" ) );
} );

} )( document, window );