How do you animate navigation in Windows 8 Metro Apps?

依然范特西╮ 提交于 2019-12-23 20:18:44

问题


In Metro apps that use HTML it is recommended to use fragments to navigate to different page (explained here).

How can you animate navigation between fragments without writing lots of code?

1) The navigate method is shown in many examples, but doesn't seem to have animation control:

WinJS.Navigation.navigate('/html/myNextPage.html');

2) The is a method WinJS.UI.Animation.enterPage, but do you have to give up navigate's history management to use this? Also the documentation is pretty sketchy still.

Shouldn't this be a one liner because it's such a common scenario?


回答1:


WinJS has support for animations and does not interfere with Fragment navigation. Animations are visual effects that do not change history and are simple to use.

Typically you would do both at the same time:

1) Navigate to a new fragment using

WinJS.Navigation.navigate('/html/myPage.html');

2) Within myPage.js, the enterPage animation can be used:

WinJS.UI.ui.Pages.define("/html/myPage.html", {
    ready: function (element, options) {
        var offset = { top: "500px", left: "500px" };
        var el = document.getElementById("rootId")  // id of any element on myPage.html
        WinJS.UI.Animation.enterPage(el, offset);
    }
}

This will animate everything on the page, from position 500,500 to the final resting positions (assuming rootId is a containing all your other elements).




回答2:


I just wanted to add that when you define the page, one of the functions is the getAnimationElements which you can use to animate elements in your page. e.g:

WinJS.UI.ui.Pages.define("/html/myPage.html", {
    ready: function (element, options) {

    },
    getAnimationElements: function () {
        var elements = [[this.element.querySelector("yourElement1")], [this.element.querySelector("yourElement2")]];
        return elements;
    },
}

Can read more about it here:

http://msdn.microsoft.com/en-us/library/windows/apps/hh972605.aspx



来源:https://stackoverflow.com/questions/9009102/how-do-you-animate-navigation-in-windows-8-metro-apps

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!