2

如何使用 JavaScript 检查 snapview 是否正常工作。

var SNAPPED_VIEW = 320;

window.addEventListener("resize", onViewStateChanged);

function onViewStateChanged(eventArgs) {
    var viewStates = Windows.UI.ViewManagement.ApplicationViewState, msg;
    var newViewState = Windows.UI.ViewManagement.ApplicationView.value;
    if (newViewState === viewStates.snapped) {
        var msg = new Windows.UI.Popups.MessageDialog("snap view mode");
    } else if (newViewState === viewStates.filled) {
        showMenu('filled');
    } else if (newViewState === viewStates.fullScreenLandscape) {
        showMenu('landscape');
    } else if (newViewState === viewStates.fullScreenPortrait) {
        //Currently not supported
    }
}

我正在尝试使用此代码,但在使用断点时显示未定义。

4

2 回答 2

1

我最近想出了一个解决方案。它不是特定于 Windows 8 应用程序的,因此不需要Windows.UI.

http://menacingcloud.com/?c=targetSnapMode

@viewport声明结合使用时,它可以形成有效的组合。

@-ms-viewport { width: device-width; } @viewport { width: device-width; }

上述@viewport声明在http://menacingcloud.com/?c=cssViewportOrMetaTag进行了讨论

于 2013-06-14T18:55:15.680 回答
0

正如吉姆所说,你的代码工作得很好,但你没有显示你的对话框。我刚刚添加了一个文本框并为不同的视图分配了值,它工作得非常好:

var SNAPPED_VIEW = 320;

window.addEventListener("resize", onViewStateChanged);

function onViewStateChanged(eventArgs) {
   var viewStates = Windows.UI.ViewManagement.ApplicationViewState, msg;
   var newViewState = Windows.UI.ViewManagement.ApplicationView.value;
   if (newViewState === viewStates.snapped) {
    document.getElementById("screenMode").innerText = "s";
   } else if (newViewState === viewStates.filled) {
    document.getElementById("screenMode").innerText = "f";
   } else if (newViewState === viewStates.fullScreenLandscape) {
    document.getElementById("screenMode").innerText = "l"
   } else if (newViewState === viewStates.fullScreenPortrait) {
    //Currently not supported
   }
}

HTML:

<input type="text" id="screenMode"/>
于 2013-08-22T15:59:31.187 回答