wolegca.github.io/js/drag.js

28 lines
631 B
JavaScript
Raw Normal View History

2019-09-12 23:24:39 +08:00
(function (document) {
2019-09-19 00:24:33 +08:00
//Usage: $("#from").Drag($("#target"))
2019-09-12 23:24:39 +08:00
//Author: hooyes
2019-09-19 00:24:33 +08:00
//Modified by: 老中医
2019-09-12 23:24:39 +08:00
$.fn.Drag = function (target) {
var M = false;
var Rx, Ry;
var t = $(this);
t.mousedown(function (event) {
event.stopPropagation();
Rx = event.pageX - (parseInt(target.css("left")) || 0);
Ry = event.pageY - (parseInt(target.css("top")) || 0);
M = true;
})
.mouseup(function (event) {
M = false;
2019-09-13 15:52:47 +08:00
//t.fadeTo(20, 1);
2019-09-12 23:24:39 +08:00
});
$(document).mousemove(function (event) {
if (M) {
target.css({
top: event.pageY - Ry,
left: event.pageX - Rx
});
}
});
}
})(document);