我正在尝试根据iPad方向启用/禁用插件。
我从这开始:https://jsfiddle.net/4hnr2ef8/
然后我发现this article推荐这种方法我现在有了这个,但语法是否正确?我一直关闭看似开放但没有运气的区域: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。
答案 0 :(得分:0)
在浏览器支持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";
}