duan0821 2011-09-28 03:42
浏览 39
已采纳

如果浏览器支持js,如何显示加载动画

I want to show loading animation if browser supports js. if javascript is disabled then the image will show but never be hidden, in this case. For this purpose I wrote this code directly after tag

<?php
$results = get_browser();
if ($results["javascript"] == 1) {
echo '<div id="loading"><img src="core/design/img/load/load.gif"/></div>';
}
?>

And my js looks like that

$(window).load(function(){
$('#loading').fadeOut(600); 
}); 

Got error message browscap ini directive not set in Any suggestion to realize my idea? Please help

  • 写回答

3条回答 默认 最新

  • dongyan7988 2011-09-28 03:48
    关注

    You can just use:

    <body>
    //set the div to hidden by default
    <div id="loading" style="display:none"><img src="core/design/img/load/load.gif"/></div>
    //place this code directly below the loading div, it will run before page/dom is loaded
    <script type="text/javascript">
        document.getElementById('loading').style.display = 'block';
    </script>
    <script type="text/javascript">
        $(function() {
            //this will run after the page has loaded
            $('#loading').fadeOut(600);
        });
    </script>
    ...
    

    If you want to do exactly what aquastyle.az does (though the above solution is faster), You can do this:

    <body>
    <script type="text/javascript">
        //if JavaScript is enabled, append the loading div to be body
        $('body').append('<div id="loading"><img src="core/design/img/load/load.gif" /></div>');
    </script>
    <script type="text/javascript">
        $(function() {
            //this will run after the page has loaded
            $('#loading').fadeOut(600);
        });
    </script>
    ...
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(2条)

报告相同问题?

悬赏问题

  • ¥15 python的qt5界面
  • ¥15 无线电能传输系统MATLAB仿真问题
  • ¥50 如何用脚本实现输入法的热键设置
  • ¥20 我想使用一些网络协议或者部分协议也行,主要想实现类似于traceroute的一定步长内的路由拓扑功能
  • ¥30 深度学习,前后端连接
  • ¥15 孟德尔随机化结果不一致
  • ¥15 apm2.8飞控罗盘bad health,加速度计校准失败
  • ¥15 求解O-S方程的特征值问题给出边界层布拉休斯平行流的中性曲线
  • ¥15 谁有desed数据集呀
  • ¥20 手写数字识别运行c仿真时,程序报错错误代码sim211-100