为我的网站创建Loader

时间:2016-08-03 06:48:18

标签: javascript jquery ruby-on-rails ruby-on-rails-4 turbolinks

我正在尝试为我的网站创建加载程序,但它无法正常工作。我正在使用turbolinks经典进行此操作。加载程序在页面加载后加载,我不想要。我需要当页面加载那个时间我需要我的加载器加载,当页面加载时,加载器应该消失,这两件事都不起作用。这是我的代码

 <div id="content-wrapper">
        <div class="loader"><img src='/assets/gionee-loader.gif' style='width:100px;height:100px;margin-left:30%;margin-top:10%;display:block;'/></div>
        <div class="row">
            <div class="col-lg-12">
                <div class="main-box clearfix">
                    <div class="clearfix">
                       <div class="common_page gsb1">
                           <div class="hdr">
                               <div class="row">
                                    <div class="col-md-3">
                                      <h4>Dashboard</h4>
                                    </div>
                                <div class="col-md-5">
                                </div>
                                <div class="col-md-4 pull-right">
                                    <%=render 'common/date'%>
                                </div>                
                            </div>    
                        </div> 
                    </div>
                </div>
            </div>
        </div>
    </div>
          <center>
<div class="table-responsive custom-bg">
<table class="custom-table" cellspacing="0">

<tr>

<td><table width="100%" border="0" class="tbl-second-lvl" cellspacing="0" cellpadding="0">

  <tr>
    <td> Name</td>
    <td>Email </td>

    </tr>
<tr></tr>
 <%@dashboard.each do |dashboard|%>
  <tr>
    <td><b><%=dashboard[:NAME]%></b></td>
    <td><%=dashboard[:email]%></td>


  </tr>
  <%end%>





</table></td>  
</tr>

</table>
<%= will_paginate @dashboard %>
</div>
</center>
          <%=render 'common/footer'%>
   </div>

 <script>
    $("#retailer").attr("class","active")



    $(document).on('page:load', function(event) {
      $('.loader img').css("display","none"); 
    });


  </script>   

但是加载器没有加载图像任何人都可以告诉我该怎么做。我不想用ajax来做这件事

1 个答案:

答案 0 :(得分:0)

将display设置为最初阻止: -

         <div class="loader"><img src='/assets/gionee-loader.gif' style='width:100px;height:100px;margin-left:30%;margin-top:10%;display:block;'/></div>

或只是

<div class="loader"><img src='/assets/gionee-loader.gif' style='width:100px;height:100px;margin-left:30%;margin-top:10%;'/></div>

并删除

$(document).on('page:before-unload', function(event) {
//remove  $('.loader img').css("display","block");
});

因此,在文档完全加载后,加载程序图像将不可见,但在此之前可见