首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >预加载器不会停止,也不会转换到主页

预加载器不会停止,也不会转换到主页
EN

Stack Overflow用户
提问于 2016-09-04 23:43:10
回答 1查看 11.3K关注 0票数 3

我的预加载器不会停止加载,也不想转换到主页。预加载器应该加载3-4秒,然后自动转换到页面。我试过删除jquery/javascript中的东西。但是我找不到解决这个问题的办法。

我也在网上寻找解决方案,但没有一个对我有帮助。

提前感谢您的帮助。

代码语言:javascript
复制
jQuery(document).ready(function($) {

    // site preloader -- also uncomment the div in the header and the css style for #preloader
    $(window).load(function() {
        $('#preloader').fadeOut('slow', function() {
            $(this).remove();
        });
    });

});
代码语言:javascript
复制
.js div#preloader {
    position: fixed;
    left: 0;
    top: 0;
    z-index: 999;
    width: 100%;
    height: 100%;
    overflow: visible;
    background: #333 url('http://files.mimoymima.com/images/loading.gif') no-repeat center center;
}
代码语言:javascript
复制
<?php
/**
* Maintenance mode template. This is shown to anyone that is logged out or not an administrator!
* @package    maintenance-mode
* @copyright  Copyright (c) 2016, ZartanLOL
* @license    GPL2+
*/
 ?>

 <!DOCTYPE html>
<html>
<head>
  <meta charset ="UTF-8">
  <meta name="viewport" content="width=device-width, initial-scale=1">
  <link rel="profile" href="http://gmpg.org/xfn/11">

  <link href="//fonts.googleapis.com/css?family=Roboto+Slab:400,700" rel="stylesheet" type="text/css">
  <link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/font-awesome/4.4.0/css/font-awesome.min.css">

  <link rel="stylesheet" href="<?php echo plugins_url( 'assets/css/maintenance.css', dirname( __FILE__ ) ); ?>">
  <link rel="stylesheet" href="<?php echo plugins_url( 'assets/css/mobile.css', dirname( __FILE__ ) ); ?>">
  <script src="https://ajax.googleapis.com/ajax/libs/jquery/3.1.0/jquery.min.js"></script>
  <script src="http://cdnjs.cloudflare.com/ajax/libs/modernizr/2.8.2/modernizr.js"></script>
  <script src="<?php echo plugins_url( 'assets/js/preload.js', dirname( __FILE__ ) ); ?>"></script>


  <title>Maintenance Mode</title>
</head>
<body>
  <div id="preloader"></div>
  <div class="maintenance-mobile">
    <div class="maintenance-mobile-text">
      <h1>Maintenance</h1>
      <p>This website is currently undergoing scheduled maintenance. We will be back shortly! Sorry for the inconvenience.</p>
    </div>
    <div class="maintenance-container">
      <a class="maintenance-login" href="<?php echo wp_login_url(); ?>">Go to Login Page</a>
    </div>
  </div>
  <div class="maintenance-container">
    <a class="maintenance-login" href="<?php echo wp_login_url(); ?>">Go to Login Page</a>
  </div>
</body>
</html>

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2016-09-04 23:50:59

好吧,我建议你读这篇文章:https://jquery.com/upgrade-guide/3.0/

您使用的是jQuery3,但是您使用的函数在jQuery 1.10+之后就被弃用了。

.load()已从jQuery 3中删除。文档也已准备就绪。

事件

破坏性更改:删除了.load()、.unload()和.error()

破坏性更改:已删除.on("ready",fn)

破坏性更改:删除了event.pageX和event.pageY规范化

破坏性更改:删除了jQuery.event.props和jQuery.event.fixHooks

破坏性变化:带有错误选择器的委托事件立即抛出

不推荐使用:.bind()和.delegate()

使用适当的现代jQuery功能,例如

代码语言:javascript
复制
$(function(){ // this replaces document.ready
  $(window).on("load", function(){
    $('#preloader').fadeOut('slow', function() {
      $(this).remove();
    });
  });
});

从jQuery网站获得更多信息以确认:

这些方法是事件操作的快捷方式,但有几个

限制。事件.load()方法与ajax .load()方法冲突。由于DOM方法的定义方式,.error()方法不能与window.onerror一起使用。加载如果需要按这些名称附加事件,请使用.on()方法,例如将$("img").load(fn)更改为$(img).on("load",fn)。

--作为对注释的响应;如果您只想简单地延迟加载程序的删除,它将如下所示:

代码语言:javascript
复制
$(function(){ // this replaces document.ready
  setTimeout(function(){
    $('#preloader').fadeOut('slow', function() {
      $(this).remove();
    });
   }, 1500);
});

--你有没有检查你的控制台(在windows上是f12),看看里面是否没有错误?--你有没有检查你的源代码(在windows上是ctrl+U),javascript是否真的被正确地包含了?

票数 6
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/39318672

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档