预加载重型GIF图像
我有一个重型过程,需要几秒钟才能完成。
这就是为什么我添加了一个动画加载页面以使等待可接受。
<style>
.modal_gif {
display: none;
position: fixed;
z-index: 1000;
top: 0;
left: 0;
height: 100%;
width: 100%;
background: rgba( 255, 255, 255, .8 )
url('static/loading.gif')
50% 50%
no-repeat;
background-size: 80%, auto;
}
body.loading .modal_gif {
overflow: hidden;
}
body.loading .modal_gif {
display: block;
}
</style>
<script>
$(document).on({
ajaxStart: function() { $body.addClass("loading"); },
ajaxStop: function() { $body.removeClass("loading"); }
});
</script>
但是,GIF重约1MB,在第一个请求后未显示:屏幕上只有半透明的面纱。
第二个和以下请求运行良好,这使我认为这是一个GIF加载问题。
我希望在要求时始终显示动画加载GIF,即使是第一个请求也是如此。
您知道如何将gif动画文件预加载为“隐藏”并为第一个请求显示?
I have a heavy process that requires several seconds to complete.
That's why I've added an animated loading page to make the wait acceptable.
<style>
.modal_gif {
display: none;
position: fixed;
z-index: 1000;
top: 0;
left: 0;
height: 100%;
width: 100%;
background: rgba( 255, 255, 255, .8 )
url('static/loading.gif')
50% 50%
no-repeat;
background-size: 80%, auto;
}
body.loading .modal_gif {
overflow: hidden;
}
body.loading .modal_gif {
display: block;
}
</style>
<script>
$(document).on({
ajaxStart: function() { $body.addClass("loading"); },
ajaxStop: function() { $body.removeClass("loading"); }
});
</script>
However, the gif weigh about 1MB and it is not displayed after the first request: there is only a semi-transparent veil on the screen.
The second and following requests are working well, which makes me think that it is a gif loading problem.
I'd like the animated loading gif to be always displayed when requested, even for the first request.
Do you know how to preload a gif animated file as hidden and display it even for the first request?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您可以尝试使用虚拟
img
标签(隐藏可见性,而不显示无)预加载它。如果我们这样做,您就可以首先:甚至使用不透明度0或不透明度1播放,这里的密钥是
指针 - 事件:无;
,因此可以单击图像。You can try preloading it using a dummy
img
tag (with visibility hidden, not display none). If we're at it, you can in the first place:or even play with opacity 0 or opacity 1, the key here is
pointer-events: none;
so the image is clickable through.