Reply To: Track Mouse Position

PennController for IBEX Forums Requests Track Mouse Position Reply To: Track Mouse Position

#8431
Jeremy
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