-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
26b67b7
commit b160373
Showing
5 changed files
with
78 additions
and
4 deletions.
There are no files selected for viewing
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file not shown.
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 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
const viewportDimensions = { | ||
x: 50000, | ||
y: 50000, | ||
}; | ||
|
||
document.addEventListener("load", function () { | ||
const scrollableArea = document.getElementById("scrollable-area"); | ||
const viewportWidth = window.innerWidth; | ||
const viewportHeight = window.innerHeight; | ||
|
||
// Calculate the center position | ||
const scrollToX = (viewportDimensions.x - viewportWidth) / 2; | ||
const scrollToY = (viewportDimensions.y - viewportHeight) / 2; | ||
|
||
console.log(`Center is: ${scrollToX}, ${scrollToY}`); | ||
// Set the initial scroll position | ||
window.scrollTo(scrollToX, scrollToY); | ||
|
||
// Prevent default touch behavior to allow custom scrolling | ||
scrollableArea.addEventListener( | ||
"touchmove", | ||
function (e) { | ||
e.preventDefault(); | ||
}, | ||
{ passive: false } | ||
); | ||
|
||
let startX, startY, scrollLeft, scrollTop; | ||
|
||
scrollableArea.addEventListener("touchstart", function (e) { | ||
startX = e.touches[0].pageX - scrollableArea.offsetLeft; | ||
startY = e.touches[0].pageY - scrollableArea.offsetTop; | ||
scrollLeft = window.pageXOffset || document.documentElement.scrollLeft; | ||
scrollTop = window.pageYOffset || document.documentElement.scrollTop; | ||
}); | ||
|
||
scrollableArea.addEventListener("touchmove", function (e) { | ||
const x = e.touches[0].pageX - scrollableArea.offsetLeft; | ||
const y = e.touches[0].pageY - scrollableArea.offsetTop; | ||
const walkX = (x - startX) * 2; // Adjust scrolling speed if needed | ||
const walkY = (y - startY) * 2; | ||
window.scrollTo(scrollLeft - walkX, scrollTop - walkY); | ||
}); | ||
}); |
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