dongyun6835 2015-11-20 12:48
浏览 65

在页面加载时显示div上方的giv [关闭]

Well I want to show a gif image while the page is loading so I can make any action on the original div, Here is my code:

<?php
echo"<input type='submit' value='Rechercher' name='rechercher'  id='submit' onclick='display_loader()'/>";
?>
<div id="loader">

</div>

my javascript function:

<script>
    function display_loader()
    {
        document.getElementById('loader').innerHTML = "<img src='load.gif' alt='load'/><br/>Loading, please wait ...";
    }
</script>

The current solution allows me to display the gif image, but I really want it to display it above the original div.

  • 写回答

2条回答 默认 最新

  • drgm51600 2015-11-20 12:55
    关注

    HTML:

     <div id="loader" class="visible">
          <img src='load.gif' alt='load'/><br/>Loading, please wait ...
     </div>
    

    CSS:

    #loader {
        position: fixed;
        width: 100%;
        height: 100%;
        background: rgba(0,0,0,0.7);
        z-index: 999;
    }
    
    #loader img {
        // position of your image on the screen
    }
    
    .hidden { display: none; }
    .visible{ display: block; }
    

    JS:

    var loader = document.getElementById('#loader');
    
    function showLoader() {
        loader.classList.remove('hidden');
        loader.classList.add('visible');
    }
    
    function hideLoader() {
        loader.classList.remove('visible');
        loader.classList.add('hidden');
    }
    

    More about classList (and its support read here - https://developer.mozilla.org/en-US/docs/Web/API/Element/classList)

    评论

报告相同问题?

悬赏问题

  • ¥20 数学建模,尽量用matlab回答,论文格式
  • ¥15 昨天挂载了一下u盘,然后拔了
  • ¥30 win from 窗口最大最小化,控件放大缩小,闪烁问题
  • ¥20 易康econgnition精度验证
  • ¥15 msix packaging tool打包问题
  • ¥28 微信小程序开发页面布局没问题,真机调试的时候页面布局就乱了
  • ¥15 python的qt5界面
  • ¥15 无线电能传输系统MATLAB仿真问题
  • ¥50 如何用脚本实现输入法的热键设置
  • ¥20 我想使用一些网络协议或者部分协议也行,主要想实现类似于traceroute的一定步长内的路由拓扑功能