Created
July 29, 2024 07:24
-
-
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 file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* 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