adding a Mouse Wheel Scroll Event

main
Amēlija I 2025-03-22 17:14:00 +02:00
parent e9a5d6bbf9
commit 3e4a53e8ba
1 changed files with 22 additions and 0 deletions

View File

@ -123,6 +123,28 @@ document.addEventListener("mousedown", (event) => {
sendDataToServer(eventData);
});
function debounce(func, wait) {
let timeout;
return function(...args) {
clearTimeout(timeout);
timeout = setTimeout(() => func.apply(this, args), wait);
};
}
let accumulatedPixels = 0;
const handleWheel = debounce((event) => {
const direction = accumulatedPixels > 0 ? "вниз" : "вверх";
const pixels = Math.abs(accumulatedPixels);
const eventData = createEventJSON('wheel', { direction, pixels: `${pixels}px`, description: "Прокрутка колёсика мыши"});
console.log("Событие wheel:", JSON.stringify(eventData));
sendDataToServer(eventData);
accumulatedPixels = 0;
}, 200);
document.addEventListener("wheel", (event) => { accumulatedPixels += event.deltaY; handleWheel(event);});
document.addEventListener("click", (event) => {
const eventType = 'click';