Skip to content

Instantly share code, notes, and snippets.

@ScottMaclure
Created October 2, 2012 04:31
Show Gist options
  • Save ScottMaclure/3816175 to your computer and use it in GitHub Desktop.
Save ScottMaclure/3816175 to your computer and use it in GitHub Desktop.
Gutter clicks on page
$("body").off("click");
$("body").on("click", function(event) {
console.log("body click pageX: " + event.pageX + " pageY: " + event.pageY);
if (typeof event.pageX === "undefined" || typeof event.pageY === "undefined") {
console.log("Not a user-originated click event, aborting.");
return;
}
if (event.pageX === 0 && event.pageY === 0) {
console.log("Not a user-originated click event, aborting.");
return;
}
var globalHeaderWidth = $("#global_header").width()
// Gutter width is window width, less the main content area, divided by 2 (we have left/right gutters).
var gutterWidth = ($(window).width() - globalHeaderWidth) / 2;
if (event.pageX < gutterWidth) {
console.log("left gutter click");
} else if (event.pageX > gutterWidth + globalHeaderWidth) {
console.log("right gutter click");
}
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment