我在下面找到了这个方向测试代码,寻找JQTouch参考资料.这在移动Safari上的iOS模拟器中正常工作,但在Phonegap中无法正确处理.我的项目遇到了与杀死此测试页面相同的问题.有没有办法在Phonegap中使用JavaScript来感知方向变化?
window.onorientationchange = function() {
/*window.orientation returns a value that indicates whether iPhone is in portrait mode, landscape mode with the screen turned to the
left, or landscape mode with the screen turned to the right. */
var orientation = window.orientation;
switch (orientation) {
case 0:
/* If in portrait mode, sets the body's class attribute to portrait. Consequently, all style definitions matching the body[class="portrait"] declaration
in the iPhoneOrientation.css file will be selected and used to style "Handling iPhone or …Run Code Online (Sandbox Code Playgroud) 我正在构建一个iPhone Web应用程序,并希望将方向锁定为纵向模式.这可能吗?是否有任何网络工具包扩展来执行此操作?
请注意,这是一个用HTML和JavaScript编写的Mobile Safari应用程序,它不是用Objective-C编写的本机应用程序.
当用户单击网站上的按钮时,我试图让 div 全屏显示。
唯一的问题是,除了 IOS 上的 Safari 之外,每个浏览器似乎都想工作。
我需要做什么才能使其全屏显示?我试过研究,但找不到任何东西。
继承人我目前的代码:
<script type="text/javascript">
function goFullscreen(id) {
var element = document.getElementById(id);
var isInFullScreen = (document.fullscreenElement && document.fullscreenElement !== null) ||
(document.webkitFullscreenElement && document.webkitFullscreenElement !== null) ||
(document.mozFullScreenElement && document.mozFullScreenElement !== null) ||
(document.msFullscreenElement && document.msFullscreenElement !== null);
var docElm = document.documentElement;
if (!isInFullScreen) {
if (element.requestFullscreen) {
element.requestFullscreen();
} else if (element.mozRequestFullScreen) {
element.mozRequestFullScreen();
} else if (element.webkitRequestFullScreen) {
element.webkitRequestFullScreen();
} else if (element.msRequestFullscreen) {
element.msRequestFullscreen();
}
} else {
if (document.exitFullscreen) …Run Code Online (Sandbox Code Playgroud) 我们在 Ipad 上有一个 PWA,其中清单文件明确指示它应该在横向模式下运行,但我仍然可以在应用程序上旋转屏幕。
这是我的manifest文件
"name": "App",
"short_name": "App",
"theme_color": "rgba(33,150,243,0)",
"background_color": "rgba(33,150,243,0)",
"display": "standalone",
"orientation": "landscape",
"Scope": "/",
"start_url": "/",
"prefer_related_application" : false,
"icons": [
{
"src": "images/icons/icon-72x72.png",
"sizes": "72x72",
"type": "image/png"
}
],
"splash_pages": null
}
Run Code Online (Sandbox Code Playgroud)
如您所见,"orientation": "landscape",已设置,但其行为并非如此。知道如何在 PWA 中强制执行它吗?
javascript ×3
ios ×2
iphone ×2
safari ×2
cordova ×1
html ×1
ipad ×1
jqtouch ×1
jquery ×1
orientation ×1