Skip to content

Commit

Permalink
inertia scrolling in demo, improvements to touch events (closes #3, #10)
Browse files Browse the repository at this point in the history
  • Loading branch information
hakimel committed Oct 14, 2012
1 parent 227d3ca commit e349323
Show file tree
Hide file tree
Showing 4 changed files with 43 additions and 27 deletions.
4 changes: 4 additions & 0 deletions README.md
Expand Up @@ -95,6 +95,10 @@ meny.addEventListener( 'close', function() {


## History ## History


#### 1.2
- Improvements to touch interaction
- Setting threshold to 0 disables hover/touch-to-open

#### 1.1 #### 1.1
- Instances of Meny now dispatch 'open'/'close' events - Instances of Meny now dispatch 'open'/'close' events


Expand Down
2 changes: 2 additions & 0 deletions css/demo.css
Expand Up @@ -135,6 +135,8 @@ h2 {
height: 100%; height: 100%;
overflow-y: auto; overflow-y: auto;


-webkit-overflow-scrolling: touch;

-webkit-box-sizing: border-box; -webkit-box-sizing: border-box;
-moz-box-sizing: border-box; -moz-box-sizing: border-box;
box-sizing: border-box; box-sizing: border-box;
Expand Down
44 changes: 27 additions & 17 deletions js/meny.js
@@ -1,5 +1,5 @@
/*! /*!
* meny 1.1 * meny 1.2
* http://lab.hakim.se/meny * http://lab.hakim.se/meny
* MIT licensed * MIT licensed
* *
Expand Down Expand Up @@ -90,7 +90,9 @@ var Meny = {
setupMenu(); setupMenu();
setupContents(); setupContents();


bindEvents(); if( config.threshold ) {
bindEvents();
}


/** /**
* Prepares the transforms for the current positioning * Prepares the transforms for the current positioning
Expand Down Expand Up @@ -273,11 +275,15 @@ var Meny = {
* Attaches all input event listeners. * Attaches all input event listeners.
*/ */
function bindEvents() { function bindEvents() {
Meny.bindEvent( document, 'mousedown', onMouseDown ); if( 'ontouchstart' in window ) {
Meny.bindEvent( document, 'mouseup', onMouseUp ); Meny.bindEvent( document, 'touchstart', onTouchStart );
Meny.bindEvent( document, 'mousemove', onMouseMove ); Meny.bindEvent( document, 'touchend', onTouchEnd );
Meny.bindEvent( document, 'touchstart', onTouchStart ); }
Meny.bindEvent( document, 'touchend', onTouchEnd ); else {
Meny.bindEvent( document, 'mousedown', onMouseDown );
Meny.bindEvent( document, 'mouseup', onMouseUp );
Meny.bindEvent( document, 'mousemove', onMouseMove );
}
} }


/** /**
Expand Down Expand Up @@ -421,17 +427,21 @@ var Meny = {


// Check for swipe gestures in any direction // Check for swipe gestures in any direction


if( touchMoveX < touchStartX - config.threshold ) { if( Math.abs( touchMoveX - touchStartX ) > Math.abs( touchMoveY - touchStartY ) ) {
swipeMethod = onSwipeRight; if( touchMoveX < touchStartX - config.threshold ) {
} swipeMethod = onSwipeRight;
else if( touchMoveX > touchStartX + config.threshold ) { }
swipeMethod = onSwipeLeft; else if( touchMoveX > touchStartX + config.threshold ) {
} swipeMethod = onSwipeLeft;
else if( touchMoveY < touchStartY - config.threshold ) { }
swipeMethod = onSwipeDown;
} }
if( touchMoveY > touchStartY + config.threshold ) { else {
swipeMethod = onSwipeUp; if( touchMoveY < touchStartY - config.threshold ) {
swipeMethod = onSwipeDown;
}
else if( touchMoveY > touchStartY + config.threshold ) {
swipeMethod = onSwipeUp;
}
} }


if( swipeMethod && swipeMethod() ) { if( swipeMethod && swipeMethod() ) {
Expand Down
20 changes: 10 additions & 10 deletions js/meny.min.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit e349323

Please sign in to comment.