Created
May 16, 2013 09:45
-
-
Save rambuvn/5590620 to your computer and use it in GitHub Desktop.
developing facebook menu
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var ondrag = false, | |
pointStart = lastPoint = distance = currentTranslate = 0; | |
$(window).on('mousedown mousemove mouseup touchmove touchstart touchend',function(event){ | |
console.log( event ); | |
switch(event.type) { | |
case 'touchstart': | |
case 'mousedown': | |
ondrag = true; | |
pointStart = lastPoint = event.pageX || event.originalEvent.touches[0].pageX; | |
break; | |
case 'mousemove': | |
case 'touchmove': | |
if( ondrag ) { | |
var mousepoint = event.pageX || event.originalEvent.touches[0].pageX; | |
var direction = mousepoint - lastPoint; | |
distance = mousepoint - pointStart; | |
currentTranslate += direction; | |
if( currentTranslate > navW ) { | |
currentTranslate = navW; | |
} | |
if( currentTranslate < 0 ) { | |
currentTranslate = 0; | |
} | |
translate( currentTranslate , $('#main, .handheld-header'), 'px' ); | |
lastPoint = mousepoint; | |
} | |
break; | |
case 'mouseup': | |
case 'touchend': | |
ondrag = false; | |
if( currentTranslate > navW / 100 * 70 ) { | |
currentTranslate = navW; | |
translate( navW, $('#main, .handheld-header'), 'px' ); | |
} else { | |
currentTranslate = 0; | |
translate( 0, $('#main, .handheld-header'), 'px' ); | |
} | |
distance = pointStart = lastPoint = 0; | |
break; | |
} | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment