Open and close a menu with the same button.

I have a vertical menu that appears at the touch of a button, with this code.

export function iconButton1_click(event) {
    $w("#horizontalMenu1").show ()

}

What I cannot solve is how to close that menu by clicking the same button, when the menu is open.

From already thank you very much.

Hi felipebenjamin,
you could add a on_click event on the page:

export function iconButton1_click(event) {
    $w("#horizontalMenu1").show ()

}
export function page1_click(event) {
    $w("#horizontalMenu1").hide ()

}

Or, you could just add a on_mouseIn & on_mouseOut function to the button:

export function iconButton1_mouseIn(event) {
    $w("#horizontalMenu1").show ()

}export function iconButton1_mouseOut(event) {
    $w("#horizontalMenu1").hide ()

}

Did this answer your question?:grin:

export function iconButton1_click(event) {
   if($w("#horizontalMenu1").hidden){
     $w("#horizontalMenu1").show()
}else{
  $w("#horizontalMenu1").hide()
}
}

Hey! Not sure if you figured this out, but one solution could be to have a second button directly on top of the first button, set to hidden on load . Then when the first button is pressed, it shows the menu and shows the second button, with the second button set up to close the menu. That way it would look like it’s the same button. You could even change the text of the 2nd button to say “close” if you wanted.

Something like this:

export function iconButton1_click(event) {
    $w("#horizontalMenu1").show ()
    $w("#iconButton1").hide ()
    $w("#iconButton2").show ()
}

export function iconButton2_click(event) {
    $w("#horizontalMenu1").hide ()
    $w("#iconButton1").show ()
    $w("#iconButton2").hide ()
}

@ LMeyer

Take a look above to the post of " AV digital " (he has the right solution for this issue)

export function iconButton1_click(event) {
   if($w("#horizontalMenu1").hidden){
     $w("#horizontalMenu1").show()
}else{
  $w("#horizontalMenu1").hide()
}
}