window.requestAnimFrame = (function() {
return window.requestAnimationFrame || window.webkitRequestAnimationFrame || window.mozRequestAnimationFrame || window.oRequestAnimationFrame || window.msRequestAnimationFrame ||
function(callback, element) {
return window.setTimeout(callback, 20);
};
})();
function monitorDeviceOrientation(callback){
if ( window.DeviceOrientationEvent ) {
// Listen for the deviceorientation event and handle the raw data
window.addEventListener( 'deviceorientation', function( eventData ) {
var data = {
lr: eventData.gamma, // gamma is the left-to-right tilt in degrees, where right is positive
fb: eventData.beta, // beta is the front-to-back tilt in degrees, where front is positive
dir: eventData.alpha, // alpha is the compass direction the device is facing in degrees
grav: null
};
callback( data );
}, false);
} else if ( window.OrientationEvent ) {
window.addEventListener('MozOrientation', function( eventData ) {
var data = {
lr: eventData.x * 90, // x is the left-to-right tilt from -1 to +1, so we need to convert to degrees
fb: eventData.y * -90, // y is the front-to-back tilt from -1 to +1, so we need to convert to degrees
// We also need to invert the value so tilting the device towards us (forward)
// results in a positive value.
dir: null,
grav: eventData.z // z is the vertical acceleration of the device
};
callback( data );
}, false);
}
}
$.fn.physics = function(physicalParams)...
Please Whitelist JSFiddle in your content blocker.
Help keep JSFiddle free for always by one of two ways:
Whitelist JSFiddle in your content blocker (two clicks)
Go PRO and get access to additional PRO features →
Join the 4+ million users, and keep the JSFiddle dream alive.
Ad-free
All ads in the editor and listing pages are turned completely off.
Use pre-released features
You get to try and use features (like the Palette Color Generator) months before everyone else.
Fiddle collections
Sort and categorize your Fiddles into multiple collections.
Private collections and fiddles
You can make as many Private Fiddles, and Private Collections as you wish!
Console
Debug your Fiddle with a minimal built-in JavaScript console.