I'm using deviceorientation
on a mobile site, but I don't want to capture every movement. I just want 1 per second, so I'm trying to use the throttle-debounce plugin.
My original working code looked like this...
window.addEventListener(
'deviceorientation',
function (event) {
tilt([event.alpha, event.beta, event.gamma]);
},
true);
...but when I add the throttle like so...
window.addEventListener(
'deviceorientation',
$.throttle(
1000,
function (event){
tilt([event.alpha, event.beta, event.gamma]);
}),
true);
... I get a...
Uncaught TypeError: Object function ( selector, context ) {
// The jQuery object is actually just the init constructor 'enhanced'
return new jQuery.fn.init( selector, context, rootjQuery );
} has no method 'throttle'
I'm guessing I've gotten the syntax wrong, but I've tried a couple of variations and I can't quite get it. Help?
If anyone has a better way to do the same without a plugin that would be just as good :)
©2020 All rights reserved.