使用jquery(加载)函数加载gif

使用jquery(加载)函数加载gif,jquery,loading,Jquery,Loading,我正在试图找到正确的代码语法,以便在加载函数将信息插入到我的页面时插入“加载gif” <script> ('#myinfo').load('/data/myinfo.html'); </script> ('#myinfo').load('/data/myinfo.html'); 是否必须将加载gif放入其中?根据,这是一个两步过程,没有JS: 1.将此HTML添加到需要微调器的位置: 2.添加此CSS以生成实际微调器: .loader { border: 1

我正在试图找到正确的代码语法,以便在加载函数将信息插入到我的页面时插入“加载gif”

<script>
    ('#myinfo').load('/data/myinfo.html');
</script>

('#myinfo').load('/data/myinfo.html');
是否必须将加载gif放入其中?

根据,这是一个两步过程,没有JS:

1.将此HTML添加到需要微调器的位置:

2.添加此CSS以生成实际微调器:

.loader {
border: 16px solid #f3f3f3; /* Light grey */
border-top: 16px solid #3498db; /* Blue */
border-radius: 50%;
width: 120px;
height: 120px;
animation: spin 2s linear infinite;
}

@keyframes spin {
0% { transform: rotate(0deg); }
100% { transform: rotate(360deg); }
}

//延迟脚本,直到页面被解析到DOM中
$(文档).ready(函数(){
//获取对保存gif的内容或gif本身的引用
var$loadingGif=$(选择或加载gif);
//在加载开始之前显示gif
$loadingGif.show();
//加载其他信息
$('#myinfo').load('/data/myinfo.html',function(){
//此方法在加载完成后执行
//隐藏正在加载的gif文件
$loadingGif.hide();
});
});

嗯,您需要在页面中包含加载gif,这样当页面加载时,用户将能够看到它:
,然后您需要在页面加载
$(窗口)时隐藏它
还可以阅读和-您可以使用这些全局ajax事件处理程序在任何ajax请求启动时显示动画(使用
.ajaxStart()
),并在请求完成时隐藏(使用
.ajaxComplete()
<script>
    //delay script until after the page has been parsed into the DOM
    $(document).ready(function(){
        //get a reference to whatever holds the gif, or the gif itself
        var $loadingGif = $(selectorForLoadingGif);

        //show the gif before the load starts
        $loadingGif.show();
        //load the other info
        $('#myinfo').load('/data/myinfo.html', function(){
            //this method executes after the load finishes
            //hide the loading gif
            $loadingGif.hide();
        });
    });
</script>