Skip to content

Instantly share code, notes, and snippets.

@manchunlam
Created January 19, 2012 16:01
Show Gist options
  • Save manchunlam/1640768 to your computer and use it in GitHub Desktop.
Save manchunlam/1640768 to your computer and use it in GitHub Desktop.
Tommy's Module Pattern 1
var BackgroundPositioner = (function(){
var xVal = 0,
yVal = 0;
var getCoords = function(){
return xVal + "px " + yVal + "px";
},
setCoords = function(coords){
xVal = parseInt(coords[0]);
yVal = parseInt(coords[1]);
},
move = function(direction, val){
val = 1 || val;
switch(direction){
case "up":
yVal -= val;
break;
case "down":
yVal += val;
break;
case "left":
xVal -= val;
break;
case "right":
xVal += val;
break;
}
};
return {
move: move,
setCoords: setCoords,
getCoords: getCoords
}
}());
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment