PennController for IBEX › Forums › Requests › Track Mouse Position › Reply To: Track Mouse Position
September 20, 2022 at 4:44 pm
#8431

Keymaster
Hi,
You can’t control the cursor’s position, as that would pose serious security issues. You could, in theory, center the image at the cursor’s coordinates, but that’s not how I wrote the DragDrop element. What you could do to modify the behavior of the DragDrop element is upload PennElement_dragdrop.js to your project’s Modules folder, and look for these lines in the file:
start = {x: ev.clientX, y: ev.clientY, top: rect.top, left: rect.left, old_top: ev.target.style.top, old_left: ev.target.style.left, old_position: ev.target.style.position}; $(ev.target).css({position: 'fixed', top: rect.top, left: rect.left});
and replace them with:
const newtop = ev.clientY - rect.height/2, newleft = ev.clientX - rect.width/2; start = {x: ev.clientX, y: ev.clientY, top: newtop, left: newleft, old_top: ev.target.style.top, old_left: ev.target.style.left, old_position: ev.target.style.position}; $(ev.target).css({position: 'fixed', top: newtop, left: newleft});
You’ll get a warning that the element type DragDrop is defined more than once when test-running the experiment, but other than that it should work as expected
Jeremy