Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Scrolling Behavior During Dragging with Wheel Event #259

Open
benedetto-kotzaneck opened this issue May 21, 2024 · 0 comments
Open

Scrolling Behavior During Dragging with Wheel Event #259

benedetto-kotzaneck opened this issue May 21, 2024 · 0 comments

Comments

@benedetto-kotzaneck
Copy link

I am currently working on a feature where I need to implement a scrolling behavior when a list item is being dragged. I am using the vuedraggable package for the draggable list.

The expected behavior is that when a list item is being dragged and the user scrolls the mouse wheel, the list should scroll accordingly. This is to allow the user to drag items to positions that are currently out of view due to the list's overflow.

I tried to implement this by attaching a wheel event handler to the window object. However, this does not seem to catch the wheel event when a list item is being dragged. Here is a simplified version of my current implementation:

onMounted(() => {
window.addEventListener('wheel', handleScroll);
})

onBeforeUnmount(() => {
window.removeEventListener('wheel', handleScroll);
});

function handleScroll(_event: Event) {
const event = _event as WheelEvent;
if (!isDragging.value) return;
if (draggableContainer.value) {
event.preventDefault();
draggableContainer.value.scrollTop += event.deltaY;
draggableContainer.value.scrollLeft += event.deltaX;
}
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant