Created
February 14, 2012 01:08
-
-
Save potench/1822234 to your computer and use it in GitHub Desktop.
Tilt / Scroll
This file contains 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
(function () { | |
var min_tilt = 15, // minimum the user must tilt to start the scroll | |
max_speed = 5, // maximum tilt scrolling speed | |
gravity : .3, // easing | |
velocity:0 // current velocity | |
setScroll = (function (delta) { | |
if(Math.abs(delta) > min_tilt){ // scroll | |
var cur_vel = - Math.max(-max_speed, Math.min(max_speed, (delta / min_tilt) * 3)); | |
velocity += ((cur_vel - velocity) * gravity); | |
// content.position().left += velocity; | |
} | |
}), | |
deviceorientation = null, | |
orientationchange = (function() { | |
if(deviceorientation) { | |
window.removeEventListener("deviceorientation", deviceorientation, true); | |
} | |
if(window.orientation%180===0) { // portrait | |
deviceorientation = (function(e) { | |
setScroll(e.gamma); | |
}); | |
}else { // landscape | |
deviceorientation = (function(e) { | |
setScroll(e.beta); | |
}); | |
} | |
window.addEventListener("deviceorientation",deviceorientation,true); | |
})(); | |
$(window).bind("orientationchange", orientationchange); | |
})() | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment