ducksboard / gridster.js

gridster.js is a jQuery plugin that makes building intuitive draggable layouts from elements spanning multiple columns
http://gridster.net/
MIT License
6.04k stars 1.2k forks source link

manually trigger drag event #443

Open wflemmer opened 9 years ago

wflemmer commented 9 years ago

Hello,

I'm dynamically adding elements to the grid by dragging divs into it. Once the draggable div enters the grid, add_widget is called, and a new widget is added to the grid in the position specified. At this point, the mouse is still clicked, and I need to manually trigger a drag event on the new widget in the grid, so it follows the mouse. Does anyone know how this can be accomplished?

Thank you, Wade

hwanders commented 9 years ago

Get the widget element (usually a li) as jQuery-Element and trigger a mousedown and then perhaps a mousemove event on it; for example $myWidgetLi.trigger({type:'mousedown', which:1, clientX:curMouseX, clientY:curMouseY}) with curMouseX/Y as the appropriate coordinates.

meuklight commented 9 years ago

Hi, I am trying to achieve same , i tried the same code but cant able to trigger the mousedown event , is there any other way to trigger the mouse down event ? Please reply if you got the answers . TIA.

joshua-golub commented 9 years ago

I solved a similar (but not identical) problem back on Nov 13. See my answer here. I expect you could use the simulate library to trigger the mousedown.