यदि कोई व्यक्ति प्रश्न के लिए वेबव्यू/जावास्क्रिप्ट समाधान की तलाश में है, तो नीचे ऐसा कर सकता है।
यह खिड़की पर कस्टम 'फ्लिप' घटनाओं को ट्रिगर करेगा, जिसमें 'अतिरिक्त पैरामीटर' के साथ jquery है। यह भी window.flip, window.orientation के अनुरूप सेट:
$(window).on('flip',function(ev,angle,orientation) {
console.log(angle,orientation);
alert(window.flip);
});
if (window.DeviceOrientationEvent) {
jQuery.flip = {
debug : false,
interval : 1000,
checked : false,
betaflat : 25,
gammaflat : 45,
orientation : 'portrait-primary',
angles : {
'portrait-primary' : 0,
'portrait-secondary' : 0,
'landscape-primary' : 90,
'landscape-secondary' : -90
},
timer : null,
check : function(ev) {
if (!this.checked) {
var trigger=false;
if (this.debug) console.log([ev.alpha,ev.beta,ev.gamma]);
if (ev.beta>this.betaflat) {
// if beta is big its portrait
if (this.debug) console.log('beta portrait pri');
if (this.orientation!='portrait-primary') {
this.orientation='portrait-primary';
trigger=true;
}
} else if (ev.beta<-this.betaflat) {
// if beta is big its portrait
if (this.debug) console.log('beta portrait sec');
if (this.orientation!='portrait-secondary') {
this.orientation='portrait-secondary';
trigger=true;
}
} else if (ev.gamma>this.gammaflat) {
// else if gamma is big its landscape
if (this.debug) console.log('gamma landscape pri');
if (this.orientation!='landscape-primary') {
this.orientation='landscape-primary';
trigger=true;
}
} else if (ev.gamma<-this.gammaflat) {
// else if gamma is big its landscape
if (this.debug) console.log('gamma landscape sec');
if (this.orientation!='landscape-secondary') {
this.orientation='landscape-secondary';
trigger=true;
}
}
if (trigger) {
if (this.debug) console.log('trigger flip');
window.flip = this.angles[this.orientation];
$(window).trigger('flip',[window.flip,this.orientation]);
this.checked=true;
}
}
}
}
$(document).ready(function() {
setInterval(function() {jQuery.flip.checked=false},jQuery.flip.interval);
$(window).on('deviceorientation',function(ev) { jQuery.flip.check(ev.originalEvent) });
});
} else {
if (this.debug) console.log('DeviceOrientationEvent not supported');
}
jQuery वास्तव में जरूरत नहीं है। मैं वैसे भी यह आवश्यक था।
इस पर एक नज़र डालें: http://stackoverflow.com/a/41104983/2267723 सेंसर मैनेजर का उपयोग करके यह समाधान। –