tags:

views:

91

answers:

2

I'm new to JQuery, so please bear with me =)

I have a "Menu" button that should "slide down" a menu.

My problem is that the menu is visible from the start, I want it to be hidden at first and then when clicking on the "Menu" button, should the menu "slide down" and then "slide up" again after pressing the "Menu" button again.

My HTML:

<div id="moduleMenuBtn" class="moduleMenuBtn">Menu</div>
<div id="effect">Some Content</div>

My JS code:

<script type="text/javascript">

    $(function() {
        function runEffect(){ 
            var selectedEffect = $('#slide').val();
            var options = {};
            if(selectedEffect == 'scale'){  options = {percent: 0}; }
            else if(selectedEffect == 'size'){ options = { to: {width: 200,height: 60} }; }
            $("#effect").toggle(selectedEffect,options,500);
        };

        $("#moduleMenuBtn").click(function() {
            runEffect();
            return false;
        });
    });
</script>
+2  A: 

You can just add some CSS to hide it initially, like this:

​#effect { display: none; }​

Or inline, like this:

<div id="effect" style="display: none;">Some Content</div>
Nick Craver
Awesome and easy! Love bro!
Erik Lydecker
@Nick, I can't get my "slide" effect to work? See my above code. Thanks!
Erik Lydecker
@Erik - Are you including jQuery UI?
Nick Craver
I solved this, thank you!
Erik Lydecker
+2  A: 

Just use display:none; or visibility:hidden; on the #slide element in css. Or put $('#slide').hide(); at the beginning of javascript.

Also if you want to slide up/down, jQuery has native functions slideUp(), slideDown() and slideToggle(). See jQuery documentation.

Smaug
Thank you very much! As I said I'm new to JQuery and as I can see there is no "slide" effect for my menu =(Where can I add this to my current JS code?Thanks!
Erik Lydecker