Permalink
Browse files

inertia scrolling in demo, improvements to touch events (closes #3, #10)

  • Loading branch information...
1 parent 227d3ca commit e34932397ebe1cd07ffec389b5be0d7299c18515 @hakimel committed Oct 14, 2012
Showing with 43 additions and 27 deletions.
  1. +4 −0 README.md
  2. +2 −0 css/demo.css
  3. +27 −17 js/meny.js
  4. +10 −10 js/meny.min.js
View
@@ -95,6 +95,10 @@ meny.addEventListener( 'close', function() {
## History
+#### 1.2
+- Improvements to touch interaction
+- Setting threshold to 0 disables hover/touch-to-open
+
#### 1.1
- Instances of Meny now dispatch 'open'/'close' events
View
@@ -135,6 +135,8 @@ h2 {
height: 100%;
overflow-y: auto;
+ -webkit-overflow-scrolling: touch;
+
-webkit-box-sizing: border-box;
-moz-box-sizing: border-box;
box-sizing: border-box;
View
@@ -1,5 +1,5 @@
/*!
- * meny 1.1
+ * meny 1.2
* http://lab.hakim.se/meny
* MIT licensed
*
@@ -90,7 +90,9 @@ var Meny = {
setupMenu();
setupContents();
- bindEvents();
+ if( config.threshold ) {
+ bindEvents();
+ }
/**
* Prepares the transforms for the current positioning
@@ -273,11 +275,15 @@ var Meny = {
* Attaches all input event listeners.
*/
function bindEvents() {
- Meny.bindEvent( document, 'mousedown', onMouseDown );
- Meny.bindEvent( document, 'mouseup', onMouseUp );
- Meny.bindEvent( document, 'mousemove', onMouseMove );
- Meny.bindEvent( document, 'touchstart', onTouchStart );
- Meny.bindEvent( document, 'touchend', onTouchEnd );
+ if( 'ontouchstart' in window ) {
+ 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 );
+ }
}
/**
@@ -421,17 +427,21 @@ var Meny = {
// Check for swipe gestures in any direction
- if( touchMoveX < touchStartX - config.threshold ) {
- swipeMethod = onSwipeRight;
- }
- else if( touchMoveX > touchStartX + config.threshold ) {
- swipeMethod = onSwipeLeft;
- }
- else if( touchMoveY < touchStartY - config.threshold ) {
- swipeMethod = onSwipeDown;
+ if( Math.abs( touchMoveX - touchStartX ) > Math.abs( touchMoveY - touchStartY ) ) {
+ if( touchMoveX < touchStartX - config.threshold ) {
+ swipeMethod = onSwipeRight;
+ }
+ else if( touchMoveX > touchStartX + config.threshold ) {
+ swipeMethod = onSwipeLeft;
+ }
}
- if( touchMoveY > touchStartY + config.threshold ) {
- swipeMethod = onSwipeUp;
+ else {
+ if( touchMoveY < touchStartY - config.threshold ) {
+ swipeMethod = onSwipeDown;
+ }
+ else if( touchMoveY > touchStartY + config.threshold ) {
+ swipeMethod = onSwipeUp;
+ }
}
if( swipeMethod && swipeMethod() ) {
View
Oops, something went wrong.

0 comments on commit e349323

Please sign in to comment.