【问题标题】:how to extend time of splash screen WinJS如何延长启动画面WinJS的时间
【发布时间】:2014-02-11 03:45:29
【问题描述】:

我有一个带有闪屏的 WinJS 应用程序,正如我们上次知道的那样, 让我们假设三秒钟, 我该怎么做才能让它持续五秒钟???


编辑:要分享我的代码

.HTML:刚刚将此代码添加到我的并通过添加“隐藏”属性来隐藏我的内容 div 或主 div

标题

<script src="js/extendedSplash.js"></script>

身体

<!--        SPLASH SCREEN DIV-->
    <div id="extendedSplashScreen" class="extendedSplashScreen hidden">
        <img id="extendedSplashImage" src="images/splashscreen.png" alt="Splash screen image" />
            <progress id="extendedSplashProgress" style="color: white;" class="win-medium win-ring"></progress>
    </div>
<!--        END SPLASH SCREEN DIV-->

.CSS 文件:将下一个代码添加到您的样式表文件中

/*SPLASH SCREEN FORMAT*/
.extendedSplashScreen {
    background-color:#ea0000;
    height: 100%;
    width: 100%;
    position: absolute;
    top: 0px;
    left: 0px;
    text-align: center;
}

.extendedSplashScreen.hidden {
    display: none;
}

#extendedSplashImage {
    position: absolute;
}

#extendedSplashDescription
{
    position: absolute;
    width: 100%;
    top: calc(100% - 140px);
    text-align: center;
}

#extendedSplashText
{
    font-family: 'Segoe UI Semilight';
    font-size: 11pt;
    text-align: center;
    width: 75%;
    color: #ffffff;
}
/*END SPLASH SCREEN FORMAT*/

.JS 文件 创建一个JS文件(extendedSplash.js)

(function () {
    "use strict";
    var splash      = null;  // Variable to hold the splash screen object.
    var dismissed   = false; // Variable to track splash screen dismissal status.
    var coordinates = { x: 0, y: 0, width: 0, height: 0 }; // Object to store splash screen image coordinates. It will be initialized during activation.

    function loadSplashScreen(args) {
        // Retrieve splash screen object
        splash = args.detail.splashScreen;

        // Listen for window resize events to reposition the extended splash screen image accordingly.
        // This is important to ensure that the extended splash screen is formatted properly in response to snapping, unsnapping, rotation, etc...
        window.addEventListener("resize", onResize, false);

        // Retrieve the window coordinates of the splash screen image.
        coordinates = splash.imageLocation;

        // Register an event handler to be executed when the splash screen has been dismissed.
        splash.addEventListener("dismissed", onSplashScreenDismissed, false);

        // Create and display the extended splash screen using the splash screen object.
        show(splash);

        // Listen for window resize events to reposition the extended splash screen image accordingly.
        // This is important to ensure that the extended splash screen is formatted properly in response to snapping, unsnapping, rotation, etc...
        window.addEventListener("resize", onResize, false);
    }


    // Displays the extended splash screen. Pass the splash screen object retrieved during activation.
    function show(splash) {
        var extendedSplashImage = document.getElementById("extendedSplashImage");

        // Position the extended splash screen image in the same location as the system splash screen image.
        extendedSplashImage.style.top       = splash.imageLocation.y        + "px";
        extendedSplashImage.style.left      = splash.imageLocation.x        + "px";
        extendedSplashImage.style.height    = splash.imageLocation.height   + "px";
        extendedSplashImage.style.width     = splash.imageLocation.width    + "px";

        // Position the extended splash screen's progress ring. Note: In this sample, the progress ring is not used.
        /*
        var extendedSplashProgress = document.getElementById("extendedSplashProgress");
        extendedSplashProgress.style.marginTop = splash.imageLocation.y + splash.imageLocation.height + 32 + "px";
        */

        // Once the extended splash screen is setup, apply the CSS style that will make the extended splash screen visible.
        var extendedSplashScreen = document.getElementById("extendedSplashScreen");
        WinJS.Utilities.removeClass(extendedSplashScreen, "hidden");
    }

    // Updates the location of the extended splash screen image. Should be used to respond to window size changes.
    function updateImageLocation(splash) {
        if (isVisible()) {
            var extendedSplashImage = document.getElementById("extendedSplashImage");

            // Position the extended splash screen image in the same location as the system splash screen image.
            extendedSplashImage.style.top       = splash.imageLocation.y        + "px";
            extendedSplashImage.style.left      = splash.imageLocation.x        + "px";
            extendedSplashImage.style.height    = splash.imageLocation.height   + "px";
            extendedSplashImage.style.width     = splash.imageLocation.width    + "px";

            // Position the extended splash screen's progress ring. Note: In this sample, the progress ring is not used.
            /*
            var extendedSplashProgress = document.getElementById("extendedSplashProgress");
            extendedSplashProgress.style.marginTop = splash.imageLocation.y + splash.imageLocation.height + 32 + "px";
            */
        }
    }

    // Checks whether the extended splash screen is visible and returns a boolean.
    function isVisible() {
        var extendedSplashScreen = document.getElementById("extendedSplashScreen");
        return !(WinJS.Utilities.hasClass(extendedSplashScreen, "hidden"));
    }

    // Removes the extended splash screen if it is currently visible.
    function remove() {
        if (isVisible()) {
            var extendedSplashScreen = document.getElementById("extendedSplashScreen");
            WinJS.Utilities.addClass(extendedSplashScreen, "hidden");
        }
    }

    function onResize() {
        // Safely update the extended splash screen image coordinates. This function will be fired in response to snapping, unsnapping, rotation, etc...
        if (splash) {
            // Update the coordinates of the splash screen image.
            coordinates = splash.imageLocation;
            updateImageLocation(splash);
        }
    }

    function onSplashScreenDismissed() {
        // Include code to be executed when the system has transitioned from the splash screen to the extended splash screen (application's first view).
        dismissed = true;

        // Tear down the app's extended splash screen after completing setup operations here...
        // In this sample, the extended splash screen is torn down when the "Learn More" button is clicked.
        //document.getElementById("learnMore").addEventListener("click", ExtendedSplash.remove, false);
    }

    //namespace created for accessing to certain methods created inside this JS file from external JS
    WinJS.Namespace.define("ExtendedSplash", {
        isVisible:          isVisible,
        remove:             remove,
        loadSplashScreen:   loadSplashScreen
    });
})();

在您的 default.js 中查找带有

的函数或部分

args.detail.kind === activation.ActivationKind.launch

然后添加这个

    app.onactivated = function (args) {
        if (args.detail.kind === activation.ActivationKind.launch) {
            ExtendedSplash.loadSplashScreen(args);                                  //loads extended splash screen

            // Use setPromise to indicate to the system that the splash screen must not be torn down
            // until after processAll and navigate complete asynchronously.
            args.setPromise(WinJS.UI.processAll().then(function(){
                setTimeout(function () {
                    ExtendedSplash.remove();                                        //removes splash screen
                    document.getElementById("content").removeAttribute("hidden");   //shows main screen (content and footer)
                    document.getElementById("footer").removeAttribute("hidden");
                }, 4000);
            }));

}

在我的情况下,我添加了 4 秒的延迟,然后我隐藏了我的 splashScreen

ExtendedSplash.remove();

然后我展示了我的两个主要 Div(内容和页脚)

document.getElementById("content").removeAttribute("hidden");
//显示主屏幕(内容和页脚) document.getElementById("footer").removeAttribute("hidden");

【问题讨论】:

    标签: winjs splash-screen


    【解决方案1】:

    这很容易......您只需创建一个页面,当启动画面被删除时您首先显示的页面看起来就像您的启动画面一样。

    它有完整的文档here

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2013-04-17
      相关资源
      最近更新 更多