As of OS X 10.11 (El Capitan), this functionality is built in to the operating system. Go to System Preferences > General  and turn on "Automatically hide and show the menu bar."

[![][1]][1]

Here is how it works:

[![enter image description here][2]][2]


  [1]: https://i.sstatic.net/P1DpL.png
  [2]: https://i.sstatic.net/pyRtF.gif