douji8033 2016-03-23 21:06
浏览 415

在页面加载时加载gif

I have a site that where some pages run a number of php routines that can sometimes take some time. For example, from one page there is a form:

<form action ="showdata.php">
    <input type="submit">
</form>

Assume that the target page is:

connecting to a MySQL database
performing a series of select queries to establish the data to display 
preparing the resulting page with data displayed.

I have tried putting a loading gif on the target page but it only loads briefly once I suspect the queries have completed. To do this I have the following on the target page:

CSS

.loader {
top: 50%;
left: 50%;
width:6em;
height:6em;
margin-top: -3em; 
margin-left: -3em;
border: 0px solid #ccc;
background-color: #f3f3f3;
position:fixed;
background: url('../images/page-loader.gif') no-repeat;
}

SCRIPT

<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.9.1/jquery.min.js"></script>
<script type="text/javascript">
$(window).load(function() {
    $(".loader").fadeOut("slow");
})
</script>

HTML

<div class="loader"></div>

How can I get the loading gif to be displayed correctly? IE as soon as the page is chosen. I seem to remember reading that you can get around this problem using an intervening page that displays the gif and then redirects to the target page. Is this the good way to solve this problem or is there a better way?

  • 写回答

1条回答 默认 最新

  • douwan7382 2016-03-23 21:17
    关注

    What you're going to want to do is add a loading gif to your page with the form and show it when the button is clicked. The target page will only load as soon as the server-side php stuff has been handled, so showing a loading bar as soon as you click will probably give the result you are looking for.

    For example:

    <script type="text/javascript">
    $('.submit').on('click', function() {
        $(".loader").fadeIn("slow");
    })
    </script>
    
    评论

报告相同问题?

悬赏问题

  • ¥15 虚幻5 UE美术毛发渲染
  • ¥15 CVRP 图论 物流运输优化
  • ¥15 Tableau online 嵌入ppt失败
  • ¥100 支付宝网页转账系统不识别账号
  • ¥15 基于单片机的靶位控制系统
  • ¥15 真我手机蓝牙传输进度消息被关闭了,怎么打开?(关键词-消息通知)
  • ¥15 装 pytorch 的时候出了好多问题,遇到这种情况怎么处理?
  • ¥20 IOS游览器某宝手机网页版自动立即购买JavaScript脚本
  • ¥15 手机接入宽带网线,如何释放宽带全部速度
  • ¥30 关于#r语言#的问题:如何对R语言中mfgarch包中构建的garch-midas模型进行样本内长期波动率预测和样本外长期波动率预测