Replies: 2 comments
-
How about this? let on_move = Some(on_move);
EventListener::new(&window, "mouseup", move |_event| {
on_move.take();
}); No |
Beta Was this translation helpful? Give feedback.
0 replies
-
Thanks to everyone, I solved my problem. pub fn on_mouse_drag(callback: impl Fn(&web_sys::MouseEvent) + 'static) {
let window = web_sys::window().expect("should have a window in this context");
let on_move = EventListener::new(&window, "mousemove", move |event| {
callback(event.unchecked_ref());
});
EventListener::once(&window, "mouseup", move |_event| {
let target = on_move.target();
let _ = target.remove_event_listener_with_callback_and_bool(
on_move.event_type(),
on_move.callback().as_ref().unchecked_ref(),
false,
);
})
.forget();
} |
Beta Was this translation helpful? Give feedback.
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
I want to remove mousemove event when mouseup like this, But the following code will have some problems
Essentially, I want to implement a drag-and-drop interaction where mouse movements are monitored when the mouse is clicked, and the monitoring of mouse movement events is cleared after the mouse is released.
Beta Was this translation helpful? Give feedback.
All reactions