Skip to content

Instantly share code, notes, and snippets.

@themorgantown
Created April 4, 2025 13:54
Show Gist options
  • Save themorgantown/9fa1fd0a123f7cc7127d063e701e8654 to your computer and use it in GitHub Desktop.
Save themorgantown/9fa1fd0a123f7cc7127d063e701e8654 to your computer and use it in GitHub Desktop.
stop scrolling on full screen iPad documents
<script type="text/javascript">
/**
* No-Scroll Script for Hype Documents
* Prevents vertical scrolling on HYPE_document elements
* while preserving other touch gestures
*/
(function() {
// Store original touch positions
let startY;
// Function to handle touchstart
function handleTouchStart(e) {
// Store the initial touch position
startY = e.touches[0].clientY;
}
// Function to prevent vertical scrolling on HYPE_document elements
function handleTouchMove(e) {
// Only continue if this is a HYPE_document element or its child
if (!e.target.closest('.HYPE_document')) {
return;
}
// Calculate how far the user has moved
const deltaY = e.touches[0].clientY - startY;
// Check if the element is at the top and trying to scroll down,
// or at the bottom and trying to scroll up
const element = e.target.closest('.HYPE_document');
const isAtTop = element.scrollTop <= 0;
const isAtBottom = element.scrollHeight - element.scrollTop <= element.clientHeight;
// If scrolling would move outside the bounds, prevent it
if ((isAtTop && deltaY > 0) || (isAtBottom && deltaY < 0)) {
e.preventDefault();
}
}
// Function to enable the no-scroll behavior on HYPE_document elements
function lockHypeDocScroll() {
// Find all HYPE_document elements
const hypeElements = document.querySelectorAll('.HYPE_document');
// Add listeners to each HYPE_document element
hypeElements.forEach(element => {
element.style.overscrollBehavior = 'none'; // Modern browsers
element.style.overflowY = 'hidden'; // Prevent vertical scrolling
element.addEventListener('touchstart', handleTouchStart, { passive: true });
element.addEventListener('touchmove', handleTouchMove, { passive: false });
});
}
// Function to disable the no-scroll behavior if needed
function unlockHypeDocScroll() {
const hypeElements = document.querySelectorAll('.HYPE_document');
hypeElements.forEach(element => {
element.style.overscrollBehavior = '';
element.style.overflowY = '';
element.removeEventListener('touchstart', handleTouchStart);
element.removeEventListener('touchmove', handleTouchMove);
});
}
// Initialize when the document is ready
document.addEventListener('DOMContentLoaded', function() {
// Lock HYPE_document scrolling when the page loads
lockHypeDocScroll();
// Additional iPad detection if needed
const isIPad = /iPad|iPhone|iPod/.test(navigator.userAgent) ||
(navigator.platform === 'MacIntel' && navigator.maxTouchPoints > 1);
if (isIPad) {
// Apply additional iPad-specific fixes if needed
const hypeElements = document.querySelectorAll('.HYPE_document');
hypeElements.forEach(element => {
element.style.position = 'fixed';
element.style.width = '100%';
element.style.height = '100%';
element.style.overflow = 'hidden';
});
}
});
// Make functions available globally or for Hype to call
window.HypeNoScroll = {
lock: lockHypeDocScroll,
unlock: unlockHypeDocScroll
};
// If Hype is available, make functions available there too
if (window.HYPE) {
window.HYPE.documents.lockHypeDocScroll = lockHypeDocScroll;
window.HYPE.documents.unlockHypeDocScroll = unlockHypeDocScroll;
}
})();
</script>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment