Events
Instead of adding 3 (permanent) EventListener
, you could just keep the first one: square.addEventListener('mousedown'...
and when this is triggered, add the 2 other events mouseup
and mousemove
on the document (it will also enalbe the user to move quickly)
The mouseup
event should then simply remove the 2 event listeners (you will need to keep a trace of the EventListeners
).
You can then get rid off the pushed
variable.
The square.addEventListener
could be moved inside the constructor.
##moveCursor
moveCursor
In the method moveCursor
instead of moving only if the new position is completely in the area, you could separately check the X and Y coordinates (It will then be easier to move near the edges).
##Naming
Naming
I don't find the name Cursor
to be very expressive... maybe Draggable
is a better name?
Events
Instead of adding 3 (permanent) EventListener
, you could just keep the first one: square.addEventListener('mousedown'...
and when this is triggered, add the 2 other events mouseup
and mousemove
on the document (it will also enalbe the user to move quickly)
The mouseup
event should then simply remove the 2 event listeners (you will need to keep a trace of the EventListeners
).
You can then get rid off the pushed
variable.
The square.addEventListener
could be moved inside the constructor.
##moveCursor
In the method moveCursor
instead of moving only if the new position is completely in the area, you could separately check the X and Y coordinates (It will then be easier to move near the edges).
##Naming
I don't find the name Cursor
to be very expressive... maybe Draggable
is a better name?
Events
Instead of adding 3 (permanent) EventListener
, you could just keep the first one: square.addEventListener('mousedown'...
and when this is triggered, add the 2 other events mouseup
and mousemove
on the document (it will also enalbe the user to move quickly)
The mouseup
event should then simply remove the 2 event listeners (you will need to keep a trace of the EventListeners
).
You can then get rid off the pushed
variable.
The square.addEventListener
could be moved inside the constructor.
moveCursor
In the method moveCursor
instead of moving only if the new position is completely in the area, you could separately check the X and Y coordinates (It will then be easier to move near the edges).
Naming
I don't find the name Cursor
to be very expressive... maybe Draggable
is a better name?
Events
Instead of adding 3 (permanent) EventListener
, you could just keep the first one: square.addEventListener('mousedown'...
and when this is triggerdtriggered, add the 2 other events mouseup
and mousemove
on the document (it will also enalbe the user to move quickly)
The mouseup
event should then simply remove the 2 event listeners.
You can get rid off the pushed
variable (but youyou will need to keep a trace of the EventListeners
).
ThisYou can then get rid off the pushed
variable.
The square.addEventListener
could be moved inside the constructor.
##moveCursor
In the method moveCursor
instead of moving only if the new position is completely in the area, you could separately check the X and Y coordinates (It will then be simplereasier to move near the edges).
##Naming
I don't find the name Cursor
to be very expressive... maybe Draggable
is a better name?
Events
Instead of adding 3 (permanent) EventListener
, you could just keep the first one: square.addEventListener('mousedown'...
and when this is triggerd, add the 2 other events mouseup
and mousemove
on the document (it will also enalbe the user to move quickly)
The mouseup
event should then remove the 2 event listeners.
You can get rid off the pushed
variable (but you will need to keep a trace of the EventListeners
).
This square.addEventListener
could be moved inside the constructor.
##moveCursor
In the method moveCursor
instead of moving only if the new position is completely in the area, you could separately check the X and Y coordinates (It will then be simpler to move near the edges).
##Naming
I don't find the name Cursor
to be very expressive... maybe Draggable
is a better name?
Events
Instead of adding 3 (permanent) EventListener
, you could just keep the first one: square.addEventListener('mousedown'...
and when this is triggered, add the 2 other events mouseup
and mousemove
on the document (it will also enalbe the user to move quickly)
The mouseup
event should then simply remove the 2 event listeners (you will need to keep a trace of the EventListeners
).
You can then get rid off the pushed
variable.
The square.addEventListener
could be moved inside the constructor.
##moveCursor
In the method moveCursor
instead of moving only if the new position is completely in the area, you could separately check the X and Y coordinates (It will then be easier to move near the edges).
##Naming
I don't find the name Cursor
to be very expressive... maybe Draggable
is a better name?
Events
Instead of adding 3 (permanent) EventListener
, you could just keep the first one: square.addEventListener('mousedown'...
and when this is triggerd, add the 2 other events mouseup
and mousemove
on the document (it will also enalbe the user to move quickly)
The mouseup
event should then remove the 2 event listeners.
You can get rid off the pushed
variable (but you will need to keep a trace of the EventListeners
).
This square.addEventListener
could be moved inside the constructor.
##moveCursor
In the method moveCursor
instead of moving only if the new position is completely in the area, you could separately check the X and Y coordinates (It will then be simpler to move near the edges).
##Naming
I don't find the name Cursor
to be very expressive... maybe Draggable
is a better name?