简体   繁体   English

载入页面时Javascript旋转圆圈动画不会停止

[英]Javascript spinning circle animation while loading page does not stop

So I have been sitting on this for a few hours, but can't seem to figure out why my code does not work. 因此,我已经坐了几个小时,但似乎无法弄清楚为什么我的代码不起作用。

I am trying to make an animation of a 'spinning circle' (or simular) while my page loads. 我正在尝试在页面加载时制作“旋转圆”(或类似图形)的动画。 And what I have so far basically does that, but my problem is that it does not stop, so the rest of my page does not load. 到目前为止,我基本上可以做到这一点,但是我的问题是它不会停止运行,因此页面的其余部分不会加载。

Javascript: Javascript:

// Wait for window load
$(window).load(function() {
    // Animate loader off screen
    $(".se-pre-con").fadeOut("slow");;
});

HTML: Basically just a div with a class like HTML:基本上只是一个具有以下类的div

<div class="se-pre-con"></div>

CSS 的CSS

.no - js# loader {
    display: none;
}

.js# loader {
    display: block;
    position: absolute;
    left: 100 px;
    top: 0;
}

.se - pre - con {
    position: fixed;
    left: 0 px;
    top: 0 px;
    width: 100 %;
    height: 100 %;
    z - index: 9999;
    background: url(images / loader - 64 x / Preloader_2.gif) center no - repeat# fff;
}

NOTE: I used this tutorial: https://smallenvelop.com/display-loading-icon-page-loads-completely/ 注意:我使用了本教程: https : //smallenvelop.com/display-loading-icon-page-loads-completely/

OTHER NOTE: I am writing this for an ASP.NET MVC application 其他说明:我正在为ASP.NET MVC应用程序编写此代码

Ok, so this was a really simple fix. 好的,所以这是一个非常简单的修复。 Basically I just called my script before rendering my jQuery. 基本上,我只是在渲染jQuery之前调用了脚本。 My header looked like this before: 我的标题看起来像这样:

    <head>
        <script type="text/javascript" src="~/Scripts/LoadSpinner.js">
</script>
        <meta charset="utf-8" />
        <meta name="viewport" content="width=device-width, initial-scale=1.0">
        <link rel="shortcut icon" type="image/x-icon" href="favicon.ico" />
        <title>@ViewBag.Title - DeviceManagment</title>
        @Scripts.Render("~/bundles/jquery")
        @Scripts.Render("~/bundles/jqueryui")
</script>
    </head>

All I had to do, is call my Javascript file after the Renders for my jQuery. 我要做的就是在jQuery渲染器之后调用Javascript文件。

Really simple solution, but still hope it helps someone out there. 确实很简单的解决方案,但仍希望它能帮助某个人。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM