Show menu when scrolled down
-
Hi,
Is there a way to set this menu to only show the little square button with the 3 lines when i scroll down so many pixels? If so then how can i do this?
Or is there a way to build a normal top menu in this plugin and then show the little menu button when scrolled down so far?
Thanks
-
Hey there,
Unfortunately not, you would need to create some custom JavaScript rules for that yourself.
All the best
Peter
Okay, thanks anyway.
Do you know where i would need to had the javascript to get this working? Is you plugin ran by javascript files i need to change or can i do this through a javascript editor plugin?
Thanks.
Hey there,
You can put the JavaScript wherever you like in your page as it would be completely separate and disconnected from my plugin.
All you need to do is hide the button via CSS on page load and then have your JavaScript detect the page position and unhide it when it crosses a certain threshold.
It shouldn’t be too difficult for your Web Developer to write for you.
Peter
Hi,
Thanks for the info, I will have a google and look into it. I’m the web developer just creating a new site for my mums business, I know how to write CSS and edit it quite a bit just not done JavaScript so I will look into later.
Thanks
Hey there,
It will be a good chance to learn some JavaScript 🙂
If you get stuck please post what you have and I’ll see if I can help.
Peter
Okay, thanks for the help, will probably be back later ahaha
Hey there,
No problem and you are welcome 🙂
Peter
H Peter
So ive had a look and managed to hide the nav container box by adding
.responsive-menu-button {
visibility: hidden
}into my additional CSS in wordpress. I have also got a JS script loaded into wordpress with a test script on there. I have a feeling i need to try and change the root CSS file where i can add this visibility value into so i can dictate what to do with the CSS from JavaScript but i cant find the exact file that makes the changes on the front end of the website anywhere in the plugins folder for responsive menu?
From reading online is looks like i need something like this…
$(“#divname”).hide();
$(window).scroll(function() {
if ($(window).scrollTop() > 100) {
$(“#divname”).fadeIn(“slow”);
}
else {
$(“#divname”).fadeOut(“fast”);
}
});but i see the when i inspect the page with the plugin this is is a BUTTON and not a DIV so what would i do here? Can i reference the DIV below or what is it i use to dictate the changes?
Am i able to have the CSS in my themes additional CSS section and still use java script to have it unhide on scroll or so i need the CSS somewhere else?
Ive got a bit stuck here after a while of figuring out how to add scripts etc so any help or pointers would be great help 🙂
Thanks,
Harvey
Hi Harvey,
You don’t need to put CSS anywhere specific for JavaScript to do anything, they are completely separate technologies and JavaScript doesn’t care where your CSS is held so that won’t be an issue. In fact you could have your CSS stored on the moon and JavaScript would still be ok with it.
In regards your JavaScript snippet above, it is not referencing a div anywhere so I’m not sure where the confusion about buttons is coming from. You just need to replace the ID from
divnametoresponsive-menu-button.That JavaScript is also going to hide the button too at the start, I’m not sure if that is what you want? It could be but I’m also not sure how well
fadeIn()andfadeOut()work withvisibility: hiddenin JavaScript/CSS but I’ll leave that to you to find out as I actually don’t know the answer without trying it out myself first.I would advise learning a bit more CSS and JavaScript/jQuery first and get to know how to use your browsers Inspector tools are they are invaluable for this sort of thing.
Hope that helps and all the best
Peter
Okay that clears things up for me.
Im still struggling to get things working though with this.
$(“#responsive-menu-button”).hide(); $(window).scroll(function() { if ($(window).scrollTop() > 100) { $(“#responsive-menu-button”).fadeIn(“fast”); } else { $(“#responsive-menu-button”).fadeOut(“fast”); } });Yes i am wanting this to only show when i scroll down and i am going to try and learn more as it is something i am interested in. Anyway its 2.00 in the morning here so i best get some rest. I will have a look tomorrow at some point and let you know if i get anywhere.
Thanks,
Harvey
Hey Harvey,
God it is 2.30am here too. I’m going to bed now too thanks for reminding me to do that!
Have you got a URL where this is live that I could take a look at?
Peter
No its on my local site at the moment.
I will set it all up tonight on my test site that is online, its less developed then my current local site but that shouldn’t be an issue. It will take me around 20 mins to setup later this afternoon when i finish work so i will send you the link then.
I will also have a read today and look into how to get the most out of the inspect development tools in chrome, how can you see the javascript code within chromes inspect tool?
Thanks,
Harvey
So i’ve now added your plugin to my test online site http://camerabeanbags.co.uk/test/test/
I have not yet added my functions to enqueue JS files yet as i will need to do this later when i get access to FTP and my files i need to transfer.
I did also find this code http://jsfiddle.net/vivinantony/onqn2gjj/ here and I’m guessing i would just need to amend the JS to point to ‘responsive-menu-button’ but when adding it into the console part of the chrome developer tools i cant get it to do anything unfortunately.
I will upload my JS test files later anyway and will let you know when its done.
Thanks.
Sorry for all the posts,
just got this working by using this code and adding it into the code snippet in development tools but i am wanting the button to fade. Any ideas where i would add the fade function in this code? Then i just need to add this into my JS file hopefully
myID = document.getElementById("responsive-menu-button"); var myScrollFunc = function() { var y = window.scrollY; if (y >= 200) { myID.className = "bottomMenu show" } else { myID.className = "bottomMenu hide" } }; window.addEventListener("scroll", myScrollFunc);Thanks
Hi Harvey,
I see you’ve switched from jQuery to JavaScript now so you won’t be able to use
fadeIn()andfadeOut()as they are jQuery functions.You may be able to create something similar using pure JavaScript but I wouldn’t know how to do it off the top of my head.
I just did a quick Google and native JavaScript fade functions can be found on this answer:
https://stackoverflow.com/a/6121270/1836618
Peter
The topic ‘Show menu when scrolled down’ is closed to new replies.