Simple navigation menu that needs slide-in/slide-out effect
I have a very simple navigation menu that opens onclick. However it simply pops into the screen and I would like it to "slide" down instead. I have very little JavaScript experience but I am trying to learn. I would really like to avoid JQuery if possible. Is there a way that I can simply add to the JavaScript that I have to the functions I am already using (showmenu and hidemenu) so I do not have to change the html and CSS a whole lot and it will slide? Thank you in advance for any help.
function showmenu(elmnt) {
document.getElementById(elmnt).style.visibility="visible";
}
function hidemenu(elmnt) {
document.getElementById(elmnt).style.visibility="hidden";
}
Why? We're talking about 32kb here – that's less than a medium-sized picture. But if you do want to reinvent the wheel, Google is your friend. Without trying I would take any bet that "javascript slide effect without jQuery" gives you plenty information just on the first page … and after trying this was confirmed. It should be enough to get you started at least.
Why avoid jQuery? Just load the library, then use .show() and .hide(). Done.
__________________ ^_^
If anyone knows of a website that can offer ColdFusion help that isn't controlled by neurotic, pedantic jerks* (stackoverflow.com), please PM me with a link.
* The neurotic, pedantic jerks are not the owners; just the people who are in control of the "popularity contest".
I over-simplified what I said, earlier. Load the library, give the nav elements (depending how deep the nav is) the same class name, and at the bottom of the page put your jQuery document ready declaration. Inside the declaration, use jQuery to give all elements with that class name "click" event handlers that will $(this).show(), $(this).hide(), or $(this).toggle().
EDIT: Actually, now that I think about it, give all of them .toggle() and (if you want) default one of them to .show(). Of course, this will allow the user to "expand" more than one item at a time. If you want it so that only one can be expanded at any given time, then you can make a function that will set ALL to .hide(), then open only the one with that unique ID.
__________________ ^_^
If anyone knows of a website that can offer ColdFusion help that isn't controlled by neurotic, pedantic jerks* (stackoverflow.com), please PM me with a link.
* The neurotic, pedantic jerks are not the owners; just the people who are in control of the "popularity contest".
Last edited by WolfShade; 01-17-2013 at 04:58 PM..
I honestly have never used it before and I am not sure how. I thought it would be easier to make my own script.
Don't be afraid to learn then. I'm not gonna lie, jQuery – or more like asynchronous programming –, if you never did it before, takes some times to get used to and you're likely to screw up a few times*, but it is definitely worth the trouble.
Not just that it's still easier (and safer!) than writing your own animation (keyword: browser compatibility), you will also learn something that you can use in many other scenarios. jQuery is a web standard these days.
As for your simple animation you don't even need too much jQuery Kung-Fu. It will be fairly simple and you will easily find how to do this particular thing on Google, too. Plus, what's the difference between getting familiar with a new framework and having to learn how to write it yourself? You obviously don't already know the latter either.
*) Actually I never stopped screwing up when it comes to callbacks.
Actually I think he doesn't wanna use show/hide/toggle at all. He's looking for $.slideDown().
(If anything, hide/show are the two jQuery functions I'm avoiding pretty much all the time. On mobile they can be stunningly slow compared to direct css manipulation)