A Simple Slideout Menu

I just wanted an easy slideout menu.  Click on a link, and the menu slides out from the left side of the screen.  Click on the link again, or somewhere else on the page, and the menu slides back in.  Here it is:

 

 

HTML Code

data-openwidth is the width in pixels of however wide you want the menu to be when opened.

Menu Content Here

CSS Code:

	  .slideout-content {
		display: none;
		z-index: 1999;
		position: fixed;
		top: 0;
		bottom: 0;
	  }	 	

Javascript Code:

$(document).ready(function () {
    $('#idOfOpenLink').click(OpenMenu);
});

$(document).mouseup(function (e) {
	var container = $(".slideout-content");
	var openWidth = container.attr('data-openwidth') || 300;

	//If the user clicks off the menu, close it
	//This checks to make sure the user didn't click the menu, or a child element:
	if (!container.is(e.target)  && container.has(e.target).length === 0 && container.is(":visible")) {
		MenuSlide_In(container, openWidth);
	}

});

function MenuSlide() {
	
	var container = $(".slideout-content");
	var openWidth = container.attr('data-openwidth') || 300;

	if (container.is(":visible")) {
		MenuSlide_In(container, openWidth);
	}
	else {
		MenuSlide_Out(container, openWidth);
	}
}

function MenuSlide_In(container,openWidth) {
	container.css({ width: openWidth + 'px' }).show().animate({
		width: '0px'
	}, 500, function () {
		container.hide();
	});
}

function MenuSlide_Out(container, openWidth) {
	container.css({ width: 0 }).show().animate({
		width: openWidth + 'px'
	}, 500, function () {
	});
}





Related Posts


Simple Sticky Element

The user scrolls down the page and once the scrolling reaches the top of an element of my choosing, that element sticks to the top of the window, so it's always visible from that point on...
Read Post

Removing the Horizontal Margins on a Google Chart Graph

I seem to be able to successfully modify quite a bit with google charts, but I couldn't find a good way to remove the horizontal padding to the left and right of a google graph. From what I can find, there really isn't a good way to do it...
Read Post

PHP JSON Returned As Object Instead of Array

I was returning, what I thought was an array from PHP, but it kept returning it as a json object...
Read Post

Enhancements for jPlayer Implementation

I love the jPlayer for easily being able to add modern mp3 support to web pages.  I wanted a few additional features
Read Post