mousemoveevent = function(e){
          elem.style.top =  Math.min(trial.sort_area_height - trial.stim_height, Math.max(0,(e.clientY - y))) + 'px';
          elem.style.left = Math.min(trial.sort_area_width  - trial.stim_width,  Math.max(0,(e.clientX - x))) + 'px';
        }
jspsych-free-sort
plugin for drag-and-drop sorting of a collection of images
Josh de Leeuw

documentation: docs.jspsych.org