5/8 open the menu syntax/javascript



I posted regarding this a while back and i thought i had grasped it, but i guess i just confused myself again. my issue is where it says


The issue i am having with this is why i am typing function after click. I understand after posting last time that i am now placing a function inside of the function called main. But what i just realized is i don't understand why i am typing "function." if this is another function, i have not created it yet. So what does the function called function do? i guess i am confused because so far i only have 1 function and it is called Main. What does typing the word function after click actually do? and where does the function called Function come from. If this function is literally just named Function, for this particular exercise i guess i can say it makes it really confusing to someone who is learning syntax and format etc. I would like to thank zystvan for his previous reply to my issue with this step. Looking for a little extra help understanding this syntax again.

var main = function() {
   $('.icon-menu').click(function() {
           left: '0px'
       }, 200);
         left: '285px'
       }, 200); 



If you read
you can read

.click( handler ) 
Type: Function( Event eventObject )
A function to execute each time the event is triggered.


function() {
 // anonymous Function-body

is using a so-called anonymous function....


+++++ DOM representation of push menu

If your HTML-page is loaded into memory by the Browser
the memory-layout will be build
using the rules, as defined in the Document Object Model
in short the DOM

The DOM representation of the index.html file would look like:

         |                |
        head             body
         |                |
    +----+----+      +----+-----------+
    |    |    |      |                |
   link link link  10div(.menu)     27div(.jumbotron)
                    |                 |
     +--------------+----+          29div(.icon-menu)
     |                   |             |
   13div(.icon-close)  18ul          30i (.fa
     |                   |             |  and .fa-bars)
    img       +-----+----++-----+    text  
              |     |     |     |    node
             19li  20li  21li  22li
              |     |     |     |
              a     a     a     a
              |     |     |     |
            text   text  text  text
            node   node  node  node

Now if you look at the DOM representation
the body-Tag is parent to
a 10div Element's Tree ( with class-attribute with class-name "menu" )
a 27div Element's Tree ( with class-attr. with class-name "jumbotron" set )

Now if you look in the style.css file,
with which you manage the Display of your Elements,
you will find that
the body object has the property left: 0; being set
( the body-Tree has a _start-Display at position left-0 )_

the .menu object has the property left: -285px; being set
and therefor the 10div-Tree is outside of Display.

In your 'app.js' file you are
to which you assign a so-called anonymous Function
and in the FUNCTION-BODY of this anonymous Function
we are attaching our click Event-handlers
to the HTML-Elements which are
-1 carrying the "icon-menu" class-name as class-attribute
-2 carrying the "icon-close" class-name as class-attribute
( during the assignment the function is NOT executed )

You will have to add the code-line
$(document).ready( main );
which will result in the =main= Function to be executed
AFTER the Browser has set the ready Event-flag.

++++++++++ structure P u s h M e n u function
The structure of your =main= Function should look like....

  var main= function() {
     $('.icon-menu').click( function() {
           //Your animation

     $('.icon-close').click( function() {
           //Your animation

explanation of the push-menu setup


google search
class site:jquery.com

what is CSS explained site:developer.mozilla.org