Reputation: 14773
I have the following function:
div_paper.onmousedown = function(event) {
var mouseCoords = getCoords(event);
startX = mouseCoords.x - offset[0];
startY = mouseCoords.y - offset[1];
rect = paper.rect(startX, startY, 0, 0);
document.onmousemove = doDraw;
// the function below i would like to fire once
rect.drag(drag_move, drag_start, drag_up);
};
which fires, as you can see, on every mousedown. I would like to fire the drag
function only once, after the first mousedown. Should I use jQuery .one()
for that?
Thanks in advance.
Upvotes: 0
Views: 84
Reputation: 626
This is off the cuff, but you could try:
var dragged = false;
div_paper.onmousedown = function(event) {
var mouseCoords = getCoords(event);
startX = mouseCoords.x - offset[0];
startY = mouseCoords.y - offset[1];
rect = paper.rect(startX, startY, 0, 0);
document.onmousemove = doDraw;
// the function below i would like to fire once
if (!dragged)
{
dragged = true;
rect.drag(drag_move, drag_start, drag_up);
}
};
Upvotes: 2