尝试将缓冲区符号显示为图片预加载时无限循环
我真的对此感到沮丧。所以我正在用javascript制作幻灯片,但是在加载所有图像时我想显示一个缓冲符号..
这是缓冲符号代码..如果您有更好的方法,请说出来。
function loadAnimation(){
setTimeout(
"document.getElementById('main_photo_img').src = 'images/loadBar1.jpg'", 300);
setTimeout(
"document.getElementById('main_photo_img').src = 'images/loadBar2.jpg'", 600);
setTimeout(
"document.getElementById('main_photo_img').src = 'images/loadBar3.jpg';", 900);
}
显示组成缓冲动画的 3 个图像。
我在加载图像之前播放它的代码是这样的..
while(!pic1.onload){
loadAnimation();
}
所有发生的事情都是无限循环。
I am really getting frustrated with this. So I am making a slideshow with javascript but while all the images are being loaded I would like to show a buffering symbol..
here is the buffering symbol code.. if you have a better way of doing it please speak up.
function loadAnimation(){
setTimeout(
"document.getElementById('main_photo_img').src = 'images/loadBar1.jpg'", 300);
setTimeout(
"document.getElementById('main_photo_img').src = 'images/loadBar2.jpg'", 600);
setTimeout(
"document.getElementById('main_photo_img').src = 'images/loadBar3.jpg';", 900);
}
that displays 3 images that make up a buffer animation.
my code for playing it until an image is loaded is this..
while(!pic1.onload){
loadAnimation();
}
All that happens though is an infinite loop.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
尝试这样的事情:
我可能只使用 gif 或 css 背景精灵,动态设置 src 可能是迄今为止我见过的最黑客的方法;p
Try something like this:
I'd probably just use a gif or css background sprites, setting src dynamically is probably the hackiest way to do this I've seen to date ;p
这是一个递归 setTimeout 版本,我认为这就是您正在寻找的。
再次,您可以通过以下方式停止此
操作:要立即显示第一张图像,您只需调用
但要让第一张图像在显示前等待 300 毫秒,您会这样做
Here's a recursive setTimeout version which I think is what you're looking for.
And again, you'd stop this with
To start it with the first image showing up immediately you'd simply call
But to have the first image wait 300ms before showing, you would do