if you don't have jquery UI then the following solution will help. jquery-ui was causing issues because of my projects jquery version so i had to implement a custom method to handle that. this is a solution i have done for making jquery numpad draggable.
$('.selector').drags();
$.fn.drags = function (opt) {
opt = $.extend({ handle: "" }, opt);
if (opt.handle === "") {
var $el = this;
} else {
var $el = this.find(opt.handle);
}
return $el.css('cursor', opt.cursor).on("mousedown", function (e) {
if ($(e.target).hasClass(".inner-elements-prevent-draggable")) {
return; // Don't activate drag for elements with the (sometimes inner element also becomes draggable if you handling a bootstrap package for modal or something else to prevent that you can specify here)
}
if (opt.handle === "") {
var $drag = $(this).addClass('draggable');
} else {
var $drag = $(this).addClass('active-handle').parent().addClass('draggable');
}
var z_idx = $drag.css('z-index'),
drg_h = $drag.outerHeight(),
drg_w = $drag.outerWidth(),
pos_y = $drag.offset().top + drg_h - e.pageY,
pos_x = $drag.offset().left + drg_w - e.pageX;
$drag.css('z-index', 2000).parents().on("mousemove", function (e) {
$('.draggable').offset({
top: e.pageY + pos_y - drg_h,
left: e.pageX + pos_x - drg_w
}).on("mouseup", function () {
$(this).removeClass('draggable').css('z-index', z_idx); // you can also set custom z index when drag events happen
});
});
e.preventDefault(); // disable selection
}).on("mouseup", function () {
if (opt.handle === "") {
$(this).removeClass('draggable');
} else {
$(this).removeClass('active-handle').parent().removeClass('draggable');
}
});
}