(function($){ $.fn.sidetoggle = function(options) { var settings = $.extend({ moving : null, // which object to toggle? direction : null // toggle from this side of the window }, options); return this.click(function(){ var thisdir = {}; var movethis = settings.moving; var dirpos = parseint($(movethis).css(settings.direction), 10); var menuwidth = $(movethis).outerwidth(); if (isnan(dirpos)) { console.log("please define the object's position in the css."); } if (dirpos === 0) { thisdir[settings.direction] = -menuwidth; $(movethis).animate(thisdir); } else { thisdir[settings.direction] = 0; $(movethis).animate(thisdir); } }); } }(jquery));