Drag&Drop position
Question
Hi,
I try to have the mouse position when i drag&drop a block. Is it possible to have the X position and Y position with this event or another ?
editor.on('block:drag:stop', model => [...]);
Thanks
Answers (3)
Hi, one attempt to solve this could be:
- Find the iframe of the canvas
- Find the mouse position inside the iframe
To do so, you could combine functions shared on StackOverflow.
The first step could be tackled with the function found right here: https://stackoverflow.com/a/1452885/8658366
The second step could be tackled with the function found right here: https://stackoverflow.com/a/7790764/8658366
I have combined those and set up a demo for you right here: https://jsfiddle.net/6f3rw4um/ Check the output of the console.
Good luck
Thanks artf,
I already try to catch the onmouseup or onmousemove events on the iframe (and it's work) but when i drag&drop a block the event don't trigger (maybe because the mouse is on the block image)... There is no event grapesjs to have the drop position (absolute position) ?
Thanks again !
Well, first off I am not artf :) Second, set up a demo we can work on to solve your issue.
Related Questions and Answers
Continue research with similar issue discussions.
Issue #1683
How to change id/class when new element drop on editor or render element with dynamic ip?
Hello @artf , Hope you are doing well. I have two questions regards dynamic blocks adding, 1) Is it possible to render the block with dynam...
Issue #905
[Question] need to find nessesary event.
Hello to all! When dragging block into canvas, and drop it: ... we have an event to detect, what block we drop in. ?: but when i drop block...
Issue #1617
[Question] How can I stop the drop from block:drag:start event? Also is there any event to listen Invalid target position?
First of all, I really appreciate your replies on my questions. Thank you for all. Question 1 : I've a situation where if a particular bloc...
Issue #1951
[QUESTIONS] change or add event on add component from block
is it possible ?, change the drag and drop event to on click when adding a new component, I want to add components by clicking the block th...
Paid Plugins That Match This Issue
Curated by issue keywords and label relevance to help you ship faster.
Loading paid plugin recommendations...
Browse Plugin Categories
Jump directly to plugin category pages on the marketplace.