I'm trying to make a div
draggable without using jQuery UI.
However, I'm stuck with the code below. I understand that I should use the mouse position relative to the container div
(in which the div
will be dragged) and that I should set the div
's offset relative to those values.
I just can't figure out how. Any clues?
This is the code that doesn't (of course) work:
var X, Y;
$(this).mousedown(function() {
$(this).offset({
left: X,
top: Y
});
});
$("#containerDiv").mousemove(function(event) {
X = event.pageX;
Y = event.pageY;
});
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…