processing / processing/p5.js

Issue with mouseX and mouseY when using a CSS border

Open
#7,400 6 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Bug
Dominant language
JavaScript
Stars
24k
Forks
3.8k
Avg merge
3d 16h
Merged PRs (30d)
25

Description

Most appropriate sub-area of p5.js?
  • Accessibility
  • Color
  • Core/Environment/Rendering
  • Data
  • DOM
  • Events
  • Image
  • IO
  • Math
  • Typography
  • Utilities
  • WebGL
  • Build process
  • Unit testing
  • Internationalization
  • Friendly errors
  • Other (specify if possible)
p5.js version

1.9.4

Web browser and version

130.0.6723.117 (Official Build) (64-bit) (cohort: Stable)

Operating system
Windows 10 Version 180
Steps to reproduce this
Steps:
  1. Make a canvas and in CSS give the canvas a border: canvas { border: 20px darkslategrey groove; }
  2. Go back to js and draw a rect at mouseX/Y: rect(mouseX, mouseY, 5, 5)
  3. The rect is not centered where the mouse. I think it's because the border takes up 20px of the canvas and it worked when I removed the border.
Snippet:

// Paste your code here :)
rect(mouseX, mouseY, 5, 5)

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start by reproducing the issue with a p5.js canvas styled with a 20px CSS border, then trace how mouseX and mouseY are calculated relative to the canvas. Done means drawing at mouseX/mouseY places the shape at the pointer even when the canvas has a CSS border; add or update coverage if the existing tests include mouse coordinates.

Written by the indexing model from the issue text.

Assessment

Tech stack
javascript
Domain
computer-graphics
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.