[英]How do I correct this syntax to detect ipad browser orientation
我試圖基於iPad方向啟用/禁用插件。
我從這里開始: https : //jsfiddle.net/4hnr2ef8/
然后,我發現這篇文章推薦了這種方法,現在我有了,但是語法正確嗎? 我一直關閉似乎開放但沒有運氣的區域: https : //jsfiddle.net/am86cqto/
function readDeviceOrientation() {
switch (window.orientation) {
case 0:
// Portrait
break;
$(function() {
$.scrollify({
section : ".scrollify",
sectionName: "section-name",
easing: "easeInOutCubic",
scrollSpeed: 1100
});
var s = skrollr.init({
forceHeight: false
});
case 180:
// Portrait (Upside-down)
break;
$(function() {
$.scrollify({
section : ".scrollify",
sectionName: "section-name",
easing: "easeInOutCubic",
scrollSpeed: 1100
});
var s = skrollr.init({
forceHeight: false
});
case -90:
// Landscape (Clockwise)
break;
if ($(window).width() < 768) {
$.scrollify.disable()
}
else {
$.scrollify.enable()
}
case 90:
// Landscape (Counterclockwise)
break;
if ($(window).width() < 768) {
$.scrollify.disable()
}
else {
$.scrollify.enable()
}
}
}
謝謝,凱文·W。
您必須使用這種方式,直到瀏覽器支持window.screen.orientation
function getScreenOrientation(){
return screen.width > screen.height ? "landscape" : "portrait";
}
僅在手機和平板電腦上檢測方向
function getScreenOrientation(){
if (/Mobi/.test(navigator.userAgent)) {
return screen.width > screen.height ? "landscape" : "portrait";
}
return "landscape";
}
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.