Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
DeviceOrientation event listener
Message
De
04/10/2014 03:25:29
 
 
À
Tous
Information générale
Forum:
HTML5
Catégorie:
Problèmes de navigateur
Titre:
DeviceOrientation event listener
Divers
Thread ID:
01608768
Message ID:
01608768
Vues:
52
I've been using the above with the following code (Typescript):
            var processingEvent:boolean = false;
            if (window.DeviceOrientationEvent) {
                window.addEventListener('deviceorientation', (data): void=> {
                    if (Math.abs(lastAlpha - data.alpha) < 2) { return; }
                    if (processingEvent) {
                        return;
                    };
                    processingEvent = true;

                    lastAlpha = data.alpha;
                    if (data.absolute === true && data.alpha !== null) {
                        this.deviceOrientation = Math.round(360 - data.alpha);
                        console.log(this.deviceOrientation.toString());
                        this.updateArrows();
                    }
                    processingEvent = false;
                }, false);
            } else {
                alert('DeviceOrienation not supported');
            }
I noticed the event listener could be called again before the routine has finished (the event is raised extremely frequently) so added the 'processing' flag to prevent re-entrancy. It works fine - but it also appeared to work without the check so I'm wondering whether there is any really benefit in it.

Any opinions ?

Side Rant: I've been testing this with different browsers. Firefox gives by far the best results but Chrome, which one would expect to work well on Android devices, is annoyingly flacky....
Suivant
Répondre
Fil
Voir

Click here to load this message in the networking platform