User:BakiDance/timeless.js
From Drawn to Life Wiki
You are viewing a page within the User namespace. These pages are typically designated for user-generated content, and should not be confused for canon.
Note: After saving, you may have to bypass your browser's cache to see the changes.
- Firefox / Safari: Hold Shift while clicking Reload, or press either Ctrl-F5 or Ctrl-R (⌘-R on a Mac)
- Google Chrome: Press Ctrl-Shift-R (⌘-Shift-R on a Mac)
- Internet Explorer / Edge: Hold Ctrl while clicking Refresh, or press Ctrl-F5
- Opera: Go to Menu → Settings (Opera → Preferences on a Mac) and then to Privacy & security → Clear browsing data → Cached images and files.
const ele = document.getElementsByClassName('TEMPLATE-LevelMap');
ele.scrollTop = 100;
ele.scrollLeft = 150;
let pos = { top: 0, left: 0, x: 0, y: 0 };
const mouseDownHandler = function (e) {
pos = {
// The current scroll
left: ele.scrollLeft,
top: ele.scrollTop,
// Get the current mouse position
x: e.clientX,
y: e.clientY,
};
document.addEventListener('mousemove', mouseMoveHandler);
document.addEventListener('mouseup', mouseUpHandler);
};
const mouseMoveHandler = function (e) {
// How far the mouse has been moved
const dx = e.clientX - pos.x;
const dy = e.clientY - pos.y;
// Scroll the element
ele.scrollTop = pos.top - dy;
ele.scrollLeft = pos.left - dx;
};
const mouseDownHandler = function(e) {
// Change the cursor and prevent user from selecting the text
ele.style.cursor = 'grabbing';
ele.style.userSelect = 'none';
...
};
const mouseUpHandler = function () {
document.removeEventListener('mousemove', mouseMoveHandler);
document.removeEventListener('mouseup', mouseUpHandler);
ele.style.cursor = 'grab';
ele.style.removeProperty('user-select');
};