Menu bar (buttons)

Hi
I have a menu bar in buttons.
Home
About
Features
Solutions
Blog
Contact us

“Contact us” is a different button, highlighting as a CTA
“Features” and “Solutions” has a custom drop down menu using a strip for each drop down.

I created code for show and hide the elements for each button.
Visually they look good, but these buttons do not go to the page they need to go. The buttons are links to their pages. Am I missing something here? Or do I have to add more code when there is ‘onclick’

Also is there anyway to pin the strip (for both drop down menu)? Just wondering if I am missing here something.

Please help!
Thank you!

How have you linked to the other pages?

If you have linked the element itself to the required page through the elements own link setting.
https://support.wix.com/en/article/adding-a-link-to-an-element-425878

Or have you set it through code by adding the onClick event handler function through the properties panel for that element?
https://support.wix.com/en/article/corvid-reacting-to-user-actions-using-events#targetText=About%20Events,%20Event%20Handlers,%20and,element%20with%20their%20mouse%20pointer.

If you have done one way, then you can’t use the other way too, so you either do the first option with the element link setting from within the Wix Editor itself, or you use the code option and write the click action in your code.

As for pinning, if you pin something then this will happen.
https://support.wix.com/en/article/pinning-an-element

At this moment I have adding a link for each button.
And I have onclick code (to hide and show the elements) If that is the reason it does not work that I have link and I have code of onclick, then what is to code to navigate a certain page?

@horsmancs

The menu buttons that don’t have the dropdown needed, you can either link those through the button elements own link setting or through code as well as shown below.

The onClick event handler that you have got set for the menu buttons that have the need for a dropdown are fine with the show and hide functions to show or hide the dropdown strip etc.

You just need to then setup the page links that I am assuming you have as simple text box elements from that dropdown strip either as links again through the text elements own link settings or setup your text element to go through code to the link of your required page, then it should be something like this.
https://www.wix.com/corvid/reference/wix-location.html#to

import wixLocation from 'wix-location';

// ...
export function yourMenuButton_click(event) {
wixLocation.to("/your-Wix-page-URL-here");

You can’t have a link on any button through the elements own link settings, if there is a needed dropdown strip connected to that same button which you have set up with the show and hide functions.

Another option would be to use onMouseIn and onMouseOut to show and hide the dropdown strips instead, however this would not work on mobile devices, so you would therefore need to add more elements and code to your site that will only work when shown on mobile devices.

@givemeawhisky I removed the link of the button element. Use onclick to link to the page, but it still does not work.

The mouse in and out I got with the drop downs. They work just fine. The problem is when scrolling down the site, those drop down strips stay up and not together with the header (that is frozen). That is why they need to be pinned, but they cannot be pinned.

@givemeawhisky
I have something like this (see below)
Where do I put the :

import wixLocation from 'wix-location';
 

so what I have is wrong?

export function HomeMenub_onclick(event) {
//Add your code for this event here:
$w(‘#HomeMenubselect’).show();
$w(‘#AboutMenubselect’).hide();
$w(‘#Featuresbuttonselect’).hide();
$w(‘#Solutionsbuttonselect’).hide();
$w(‘#BlogMenubselect’).hide();
$w(‘#ContactMenubselect’).hide();
}

export function HomeMenubselect_onclick(event) {
//Add your code for this event here:
$w(‘#HomeMenubselect’).link= “my-Wix-page-URL-here/”
}


Should it be this?:

import wixLocation from ‘wix-location’;
export function HomeMenub_onclick(event) {
//Add your code for this event here:
$w(‘#HomeMenubselect’).show();
$w(‘#AboutMenubselect’).hide();
$w(‘#Featuresbuttonselect’).hide();
$w(‘#Solutionsbuttonselect’).hide();
$w(‘#BlogMenubselect’).hide();
$w(‘#ContactMenubselect’).hide(); }
wixLocation.to(“/my-Wix-page-URL-here”

Thank you in advance


Okay, so say you have the five menu buttons called menu1 to menu5

The first two are the ones with the dropdown strip needed and the last three are just direct links to the page .
For the dropdown strip, you can simply have all the page links for that dropdown attached to the strip itself, so simply have one text box for each page link and drag it into the strip making sure that it says attach to strip when you do it.
https://support.wix.com/en/article/attaching-elements-to-a-box

So, for your strips I have simply adding two text box elements in the code that you can use for the page links.

Also, I’m not sure what you are exactly doing with these buttons so have left them off. You can simply re-add them if you need them

$w('#Featuresbuttonselect').hide(); 
$w('#Solutionsbuttonselect').hide(); 
$w('#BlogMenubselect').hide(); 
$w('#ContactMenubselect').hide();
}

I’m not sure why you are hiding them all when another menu button is pressed.

Remember too, that as this will be site wide on your website, you should put this in your site tab and not the page tab.

As for the code, try something like this.

import wixLocation from 'wix-location';

$w.onReady(function () {

export function menu1_click(event) { 
$w('#yourstripname1here').show(); 
$w('#yourstripname2here').hide(); 
}

export function menu2_click(event) { 
$w('#yourstripname2here').show(); 
$w('#yourstripname1here').hide(); 
}

export function textbox1_click(event) {
wixLocation.to("/my-Wix-page-URL-here");
}

export function textbox2_click(event) {
wixLocation.to("/my-Wix-page-URL-here");
}

export function textbox3_click(event) {
wixLocation.to("/my-Wix-page-URL-here");
}

export function textbox4_click(event) {
wixLocation.to("/my-Wix-page-URL-here");
}

export function menu3_click(event) {
wixLocation.to("/my-Wix-page-URL-here");
}

export function menu4_click(event) {
wixLocation.to("/my-Wix-page-URL-here");
}

export function menu5_click(event) {
wixLocation.to("/my-Wix-page-URL-here");
}
}

If you do it all through code as the above example, then please remember to take off any links that you have added through the elements own link settings in the editor.

Thank you for much for this.
To answer your question. The “select” elements are ones when the page is highlighted.
So for example:
it is black (not selected) it is #HomeMenub
it will turn red when hovering or clicking the button #HomeMenubselect

My though goes:
If you open the website.
Home is red (selected page) and the rest are black
When you click About, I will need the Home button to return to black.
Same thing when you click to the next page, the other pages remain black.

Did I go overboard with the coding?
I do know it will go back to “not selected” when I click to another page.

Just want to make sure I understand.

From you code:
It shows the navigation of where to go, but what about the color of the buttons (so people know which page they are after clicking (like what I mentioned above). There should be 2 buttons to show and hide after an onclick action, correct?

You let me know.

Thank you again!

I am getting an error, and it still does not work after adding the new coding.
So I am feeling a bit confused and wondering if I am missing something.
Thank you!

Okay you can do that already through the buttons already without the use of code.
https://support.wix.com/en/article/customizing-the-regular-hover-and-clicked-views-of-your-icon-button

However, if you are wanting them to stay the same colour like a normal menu from within Wix Editor, then yes you will have to use code.

You would also need to create a duplicate button for each menu button that is hidden on load and is setup to be the colour and style etc that you want it to be when the button is hovered over or is clicked on.

So, going on the code I posted above you would have to add something like this to the export functions.

export function menu1_click(event) { 
$w('#yourstripname1here').show(); 
$w('#yourstripname2here').hide(); 
$w('#menu1').hide();  
$w('#menu1hidden').show();  
$w('#menu2hidden').hide();  
}

export function menu2_click(event) { 
$w('#yourstripname2here').show(); 
$w('#yourstripname1here').hide();
$w('#menu2').hide(); 
$w('#menu2hidden').show();
$w('#menu1hidden').hide();     
}

Obviously, if you were wanting all five of your menu buttons to do that then you would have to add the hidden menu button part to each of the export functions for each of the five buttons,

With each one having the hide function for each of the other four buttons, so for example…

export function menu1_click(event) { 
$w('#yourstripname1here').show(); 
$w('#yourstripname2here').hide(); 
$w('#menu1').hide();  
$w('#menu1hidden').show();  
$w('#menu2hidden').hide();  
$w('#menu3hidden').hide();   
$w('#menu4hidden').hide();   
$w('#menu5hidden').hide();   
}

As for the hover function, well you would need to add a onMouse event handler function for that.


//For Mouse In//
export function menu1_onMouseIn(event) { 
$w('#menu1').hide();  
$w('#menu1hidden').show();  
}

//For Mouse Out//
export function menu1_onMouseOut(event) { 
$w('#menu1').show();  
$w('#menu1hidden').hide();  
}

Also, with the page links in the strip itself, you can also simply change those to buttons so that you can do the simple hover and clicked settings through the Wix Editor settings itself.

Just design it so that the button background is transparent and only the text is shown in a colour that changes when the user hovers over or clicks on it for example.

No point having a too fancy option with those as remember that as soon as they are clicked that they wil be moving the user onto another page and won’t be seen again.

Thank you for providing the codes.
I have done these codes already. The look of it is fine.

My main problem is when I click the button it will not go to the link of the page. So I am not sure what mistake is there with the code.

Could you rewrite the code (to see if I missed anything) to link a URL?
Should the import wixLocation from ‘wix-location’; be on the first bar?
What comes next?

Will the rest of the export function codes will be after that?

@horsmancs
You can already see that in the code sample on previous reply.

import wixLocation from 'wix-location';

$w.onReady(function () {

// rest of code.... //

export function textbox4_click(event) {
wixLocation.to("/my-Wix-page-URL-here");
}

export function menu3_click(event) {
wixLocation.to("/my-Wix-page-URL-here");
}

// rest of code...... //

@givemeawhisky
Ok, I rechecked the code, and I have the same as you had (with my buttons’ names)
But I still get an error (with a red dot)

It says: Parsing error: ‘import’ and ‘export’ may only appear at the top level.

Will the URL be (“https://www.website.com/”)
Or (/www.website.com")

Any thoughts?

@horsmancs

Paste up your code that you have used so far, as it would easier to see what you have got set up already than going back and forth with different code parts etc.

Otherwise, paste up your Wix Editor URL so that Wix Admins/Mods can have a look at your actual site for you.
@yisrael-wix

It is secure as only they themselves have the access permissions to get into your editor to view it.

@givemeawhisky

Thank you for your reply

Here is a recap again about what I have:

There are 5 buttons for the menu bar
Home About Features Solutions Contact us

Features and Solutions has their own drop down box for sub menus
Contact us is a different design than the rest (eyecatcher for CTA)

Element with the word “select” in their name is the button that is highlighted after hovering the button to click.
(before when I put the onReady code, I get an error)
All buttons on the setting are set as “none”. So no linking to anything.

What does not work: the links to the pages.

First part of the code is the URL linking
Second part of the code is the two drop down boxes
Third part of the code is the buttons while hovering and clicking, etc.


import wixLocation from ‘wix-location’;

export function HomeMenubselect_onclick(event) {
//Add your code for this event here:
wixLocation.to(“/home”);
}
export function AboutMenubselect_onclick(event) {
//Add your code for this event here:
wixLocation.to(“/about-us”);
}
export function BlogMenubselect_onclick(event) {
//Add your code for this event here:
wixLocation.to(“/blog”);
}
export function ContactMenubselect_onclick(event) {
//Add your code for this event here:
wixLocation.to(“/contact”);
}

export function HomeMenub_onMouseIn(event) {
//Add your code for this event here:
$w(‘#Featurebox’).hide();
$w(‘#Solutionbox’).hide();
}

export function HomeMenubselect_onMouseIn(event) {
//Add your code for this event here:
$w(‘#Featurebox’).hide();
$w(‘#Solutionbox’).hide();
}

export function AboutMenub_onMouseIn(event) {
//Add your code for this event here:
$w(‘#Featurebox’).hide();
$w(‘#Solutionbox’).hide();
}

export function AboutMenubselect_onMouseIn(event) {
//Add your code for this event here:
$w(‘#Featurebox’).hide();
$w(‘#Solutionbox’).hide();
}

export function Featuresbutton_onmouseIn(event) {
//Add your code for this event here:
$w(‘#Featurebox’).show();
$w(‘#Solutionbox’).hide();
$w(‘#Featuresbuttonselect’).show();
}

export function Featuresbuttonselect_onmouseIn(event) {
//Add your code for this event here:
$w(‘#Featurebox’).show();
$w(‘#Solutionbox’).hide();
$w(‘#Featuresbuttonselect’).show();
}

export function Featurebox_onmouseOut(event) {
//Add your code for this event here:
$w(‘#Featurebox’).hide();
}

export function Solutionsbutton_onmouseIn(event) {
//Add your code for this event here:
$w(‘#Solutionbox’).show();
$w(‘#Featurebox’).hide();
$w(‘#Solutionsbuttonselect’).show();
}

export function Solutionsbuttonselect_onmouseIn(event) {
//Add your code for this event here:
$w(‘#Solutionbox’).show();
$w(‘#Featurebox’).hide();
$w(‘#Solutionsbuttonselect’).show();
}

export function Solutionbox_onmouseOut(event) {
//Add your code for this event here:
$w(‘#Solutionbox’).hide();
}

export function BlogMenub_onMouseIn(event) {
//Add your code for this event here:
$w(‘#Featurebox’).hide();
$w(‘#Solutionbox’).hide();
}

export function BlogMenubselect_onMouseIn(event) {
//Add your code for this event here:
$w(‘#Featurebox’).hide();
$w(‘#Solutionbox’).hide();
}

export function ContactMenub_onMouseIn(event) {
//Add your code for this event here:
$w(‘#Featurebox’).hide();
$w(‘#Solutionbox’).hide();
}

export function ContactMenubselect_onMouseIn(event) {
//Add your code for this event here:
$w(‘#Featurebox’).hide();
$w(‘#Solutionbox’).hide();
}

export function HomeMenub_onclick(event) {
//Add your code for this event here:
$w(‘#HomeMenubselect’).show();
$w(‘#AboutMenubselect’).hide();
$w(‘#Featuresbuttonselect’).hide();
$w(‘#Solutionsbuttonselect’).hide();
$w(‘#BlogMenubselect’).hide();
$w(‘#ContactMenubselect’).hide();
}

export function AboutMenub_onclick(event) {
//Add your code for this event here:
$w(‘#HomeMenub’).show();
$w(‘#AboutMenubselect’).show();
$w(‘#Featuresbuttonselect’).hide();
$w(‘#Solutionsbuttonselect’).hide();
$w(‘#BlogMenubselect’).hide();
$w(‘#ContactMenubselect’).hide();
}

export function Featuresbutton_onclick(event) {
//Add your code for this event here:
$w(‘#HomeMenub’).show();
$w(‘#AboutMenubselect’).hide();
$w(‘#Featuresbuttonselect’).show();
$w(‘#Solutionsbuttonselect’).hide();
$w(‘#BlogMenubselect’).hide();
$w(‘#ContactMenubselect’).hide();
}

export function Solutionsbutton_onclick(event) {
//Add your code for this event here:
$w(‘#HomeMenubselect’).hide();
$w(‘#AboutMenubselect’).hide();
$w(‘#Featuresbuttonselect’).hide();
$w(‘#Solutionsbuttonselect’).show();
$w(‘#BlogMenubselect’).hide();
$w(‘#ContactMenubselect’).hide();
}

export function BlogMenub_onclick(event) {
//Add your code for this event here:
$w(‘#HomeMenubselect’).hide();
$w(‘#AboutMenubselect’).hide();
$w(‘#Featuresbuttonselect’).hide();
$w(‘#Solutionsbuttonselect’).hide();
$w(‘#BlogMenubselect’).show();
$w(‘#ContactMenubselect’).hide();
}

export function ContactMenub_onclick(event) {
//Add your code for this event here:
$w(‘#HomeMenubselect’).hide();
$w(‘#AboutMenubselect’).hide();
$w(‘#Featuresbuttonselect’).hide();
$w(‘#Solutionsbuttonselect’).hide();
$w(‘#BlogMenubselect’).hide();
$w(‘#ContactMenubselect’).show();
}


Here is a mini video of how it looks

Hopefully this gives you a clear idea.
Thank you again for your help