Skip to content

Instantly share code, notes, and snippets.

@kylehotchkiss
Created August 14, 2010 05:35
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save kylehotchkiss/524024 to your computer and use it in GitHub Desktop.
Save kylehotchkiss/524024 to your computer and use it in GitHub Desktop.
function getOffset() {
/* Get the offset for moving the nav */
var width = $(document).width();
var margin = (width - 720) / 2;
var offset = $(".place.display").offset();
var position = $(".places").css("marginLeft");
position = parseInt(position.substring(0, position.indexOf("p")));
console.log(position);
if ( margin > offset.left ) {
if ( position < 0 ) {
var displacement = (-1 * offset.left) + margin;
console.log("Rule 3: Behind margin @ " + displacement + "px.");
return position + displacement;
} else {
var displacement = margin - offset.left;
console.log("Rule 2: Behind margin @ " + displacement + "px.");
return position + displacement;
}
} else {
var displacement = offset.left - margin;
console.log("Rule 1: Ahead of margin @ " + displacement + "px.");
return position - displacement;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment