Snap View通过javascript查看

时间:2012-12-27 07:44:09

标签: javascript windows-8

如何使用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
    }
}

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

2 个答案:

答案 0 :(得分:1)

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

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

当与@viewport声明结合使用时,它会产生有效的组合。

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

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

讨论了上述@viewport声明

答案 1 :(得分:0)

就像Jim说你的代码完全正常但你没有显示你的对话框。我刚刚添加了一个文本框并为不同的视图指定了值,它完全正常:

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"/>