在加载图像之前触发img onload属性 [英] img onload attribute firing before image is loaded

查看:343
本文介绍了在加载图像之前触发img onload属性的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

亲爱的,


我确实是新手,听起来很简单。我会给你任何帮助。


我在我的标题中加载了一堆图像,但是不想在加载所有图像之前显示它们。我在显示设置为的图像周围使用 div 。然后我在最后一个调用javascript的图像上插入 onload 属性,将 style.display 更改为''''。


none 到''''的显示效果变得很好,但是在加载图像之前它会触发,所以练习的整个点都消失了。 br />

知道我做错了吗?


网站 www.maaijorn.com div 被称为 imagecontainer onload 函数被称为 ShowAll


很高兴任何提示!


亲切的问候


J?rn


PS:不要用Opera测试这个,因为那个一个不会更改显示值。这将是我的下一个挑战:-)

Dear all,

I am indeed a newbie and this may sound really simple. I would apreciate any help though.

I am loading a bunch of images in my header, but would not like to show them before all images are loaded. I use a div around the images with display set to none. Then I insert an onload attribute on the last image which calls a javascript to change the style.display to ''''.

The change of display from none to '''' works just fine, but it fires before the images are loaded, so the whole point of the exercise dissapears.

Any idea what I do wrong ?

site is www.maaijorn.com, and the div is called imagecontainer. The onload function is called ShowAll

Would be glad for any hints !

Kind regards

J?rn

PS: Don''t test this with Opera, as that one does not change the display value. That will be my next challenge :-)

展开 | 选择 | Wrap | 行号

推荐答案

我正在将此转移到javascript论坛,因为这是一个js问题,但首先提示一些。

1)你的doctype不正确。应该是:

<!DOCTYPE html PUBLIC" - // W3C // DTD XHTML 1.0 Strict // EN"

" http://www.w3 .org / TR / xhtml1 / DTD / xhtml1-strict.dtd">


2)你有57个html错误,一半,也许是''alt''错误但是可以引起DOM和js的问题。
I''m transferring this to the javascript forum because this is a js problem but a few tips first.
1) Your doctype is incorrect. Should be:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">

2) You have 57 html errors, half, perhaps, are ''alt'' errors but can cause problems with the DOM and js.



我将这个转移到javascript论坛,因为这是一个js问题但是一些首先提示。

1)您的doctype不正确。应该是:

<!DOCTYPE html PUBLIC" - // W3C // DTD XHTML 1.0 Strict // EN"

" http://www.w3 .org / TR / xhtml1 / DTD / xhtml1-strict.dtd">


2)你有57个html错误,一半,也许是''alt''错误但是可以导致DOM和js出现问题。
I''m transferring this to the javascript forum because this is a js problem but a few tips first.
1) Your doctype is incorrect. Should be:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">

2) You have 57 html errors, half, perhaps, are ''alt'' errors but can cause problems with the DOM and js.



Thanx。我想改变代码引用,但你在我面前:-)

我将xhtml从2改为1,但它没有任何区别。然而,Thanx提示 - 我会读到那个!


我确实考虑在 javascripts 中发布这个但是我决定反对它,因为我的问题是更多关于 img 标签的 onload 功能。

用于纠正该标签的用户!


亲切的问候


J?rn

Thanx. I wanted to change the code quoting, but you got in before me :-)
I changed the xhtml from 2 to 1, but it did not really make any difference. Thanx for the tip though - I will read up on that one!

I did think about posting this one in javascripts but decided against it since my question is more about the onload function of the img tag.
Thanx for correcting that one !

Kind regards

J?rn


你只为最后一张图片设置了onload。


你可以做的是使用setInterval来检查完成。所有图像的属性(非标准,但应该在大多数浏览器中都有效)。一旦加载完毕,显示div(并清除间隔)。
You''ve only set the onload for the last image.

What you could do is use a setInterval to check the "complete" property (non-standard, but should work in most browsers) of all the images. Once all have loaded, display the div (and clear the interval).


这篇关于在加载图像之前触发img onload属性的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆