Skip to content

Instantly share code, notes, and snippets.

@abdulawal39
Created July 29, 2024 07:24
Show Gist options
  • Save abdulawal39/7b5070947b586d7aaee2b0a56bbe5df4 to your computer and use it in GitHub Desktop.
Save abdulawal39/7b5070947b586d7aaee2b0a56bbe5df4 to your computer and use it in GitHub Desktop.
This snippet allows users to click and drag to flip for TNC FlipBook: https://codecanyon.net/item/pdf-viewer-for-wordpress/8182815
/**
* This function allows users to click and drag anywhere to flip
* Specifically for TNC FlipBook: https://codecanyon.net/item/pdf-viewer-for-wordpress/8182815
* Put this code in your active theme's functions.php file
*
* @return void
*/
function tnc_pvfw_support_allow_drag_flip_anywhere() {
?>
<script>
var startX;
var isDragging = false;
jQuery('#viewer').on('mousedown touchstart', function(event) {
isDragging = true;
startX = event.type === 'touchstart' ? event.originalEvent.touches[0].pageX : event.pageX;
});
jQuery('#viewer').on('mousemove touchmove', function(event) {
if (isDragging) {
var currentX = event.type === 'touchmove' ? event.originalEvent.touches[0].pageX : event.pageX;
var deltaX = currentX - startX;
if (Math.abs(deltaX) > 50) { // Adjust threshold as needed
if (deltaX > 0) {
jQuery('#viewer').turn('previous');
} else {
jQuery('#viewer').turn('next');
}
isDragging = false;
}
}
});
jQuery(document).on('mouseup touchend', function() {
isDragging = false;
});
</script>
<?php
}
add_action('tnc_pvfw_footer', 'tnc_pvfw_support_allow_drag_flip_anywhere');
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment