Skip to main content
Code Review

Return to Revisions

3 of 3
Commonmark migration

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?

oliverpool
  • 1.9k
  • 12
  • 28
default

AltStyle によって変換されたページ (->オリジナル) /