Button Code For JS
Anyone know how to make a button code in JS?
Yeah sure! Basically a button needs a few things:
1. a shape you have to click
2. code to react if you click it
First, you can draw a rectangle:
rect(200, 200, 100, 50);
Then use an if statement that detects if the mouse is pressed when hovering over the button:
if(mouseX > 150 && mouseX < 250 && mouseY > 175 && mouseY < 225 && mouseIsPressed) {
// write what you want to happen
}
Please sign in to leave a comment.