Home > database >  Why doesn’t my button work when it’s hidden?
Why doesn’t my button work when it’s hidden?

Time:05-05

I have some code here it is

function setup() {
  createCanvas(1350, 715);
  var blueskin = createButton('BLUE')
  blueskin.mousePressed(changeblue)
  blueskin.position(100,400)
  blueskin.size(50,50)
  blueskin.style('display:none')
}
function changeblue(){
  playercolr='blue'
}
<script src="https://cdn.jsdelivr.net/npm/[email protected]/lib/p5.js"></script>

When the button is not hidden it works perfectly but whenever I change it to hidden it stops working I looked some stuff up and aren’t buttons supposed to work even if hidden

CodePudding user response:

Change the style from 'display:none' to 'visiblity: hidden' and then try it

visibility:hidden hides the element

display:none removes the element from the document

CodePudding user response:

Try:

blueskin.style('display', 'none')

per p5js documentation: https://p5js.org/reference/#/p5.Element/style

The syntax should be style(property, value) rather than style(propertyAndValue)

  • Related