Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save mattdanielbrown/e9347c1b955d746f5a91fb70d59c1ae6 to your computer and use it in GitHub Desktop.
Save mattdanielbrown/e9347c1b955d746f5a91fb70d59c1ae6 to your computer and use it in GitHub Desktop.
var touchingElement = false;
var startTime;
var startX = 0,
startY = 0;
var currentX = 0,
currentY = 0;
var isOpen = false;
var isMoving = false;
var menuWidth = 0;
var lastX = 0;
var lastY = 0;
var moveX = 0; // where in the screen is the menu currently
var dragDirection = "";
var maxOpacity = 0.5;
// if you want to change this, don’t forget to change the opacity value
// of the ‘.menu--visible .menu-background’ CSS class
var init = function(element, start, move, end) {
trackableElement = element;
startTime = new Date().getTime(); // start time of the touch
addEventListeners();
}
var addEventListeners = function() {
trackableElement.addEventListener("touchstart", onTouchStart, false);
trackableElement.addEventListener("touchmove", onTouchMove, false);
trackableElement.addEventListener("touchend", onTouchEnd, false);
overlay.addEventListener("click", closeMenuOverlay, false);
// I want to be able to click the overlay and immediately close the menu
// (in the space between the actual menu and the page behind it)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment