• Resolved grafica studioidee

    (@grafica-studioidee)


    hello, i would like to make my bar toggle on and off from a single link,
    something like
    <a onclick="wptbbar_toggle1()">open/close</a>
    which would act like wptbbar_show and wptbbar_hide depending if the bar is hidden or not.
    is there already a function to do that, or how can i create it?
    Thanks in advance

    https://wordpress.org/plugins/wp-topbar/

Viewing 4 replies - 1 through 4 (of 4 total)
  • Plugin Author rfgoetz

    (@rfgoetz)

    Looking at this…

    So, I am not sure how you can open the TopBar from a link, if the TopBar is hidden.

    Where is the Link you are talking about? Somewhere on your page?

    Thread Starter grafica studioidee

    (@grafica-studioidee)

    Dear Bob, thanks for your reply.
    Unfortunately, the website I’m working on is currently under construction and not visible.
    Anyway, in the main menu, I put a link with this code:
    <a onclick="wptbbar_show1()">Open topbar 1</a>
    which is working great and displays the topbar 1.

    In the close button of this topbar, by default, there is this code:
    <img onclick="wptbbar_hide1()" src="..."></img>

    I would like to join the show and hide JS functions in a single “toggle” one, that could both show or hide the bar depending on its status.
    Thanks in advance

    Plugin Author rfgoetz

    (@rfgoetz)

    Hmm… you can try writing your own javascript function in your theme.

    I tested the code in a Chrome console and it worked for me. You might have to play with the number “40” to find what works for your TopBar.

    To find the current height, open Chrome and go to the console.
    Enter this in “document.getElementById(‘topbar1’).offsetHeight” when the TopBar is shown. My value was 41..so I subtracted one and got to 40:

    function wptbbar_toggle() {
    	   if ( document.getElementById('topbar1').offsetHeight > 40) {
                   wptbbar_hide1();
    	   }
    	   else {
    	      wptbbar_show1();
    	   }
    }
    Thread Starter grafica studioidee

    (@grafica-studioidee)

    Thank you very much Bob, it works!

Viewing 4 replies - 1 through 4 (of 4 total)

The topic ‘toggle bar in a single button or link’ is closed to new replies.