解决方法
While JavaScript provides the load event for executing code when a page is rendered,this event does not get triggered until all assets such as images have been completely received. In most cases,the script can be run as soon as the DOM hierarchy has been fully constructed. The handler passed to .ready() is guaranteed to be executed after the DOM is ready,so this is usually the best place to attach all other event handlers and run other jQuery code.
…和.load文档:
The load event is sent to an element when it and all sub-elements have been completely loaded. This event can be sent to any element associated with a URL: images,scripts,frames,iframes,and the window object.
所以.load是你要找的。这个事件的好处是可以将其附加到DOM的一个子集。假设你的幻灯片图像是像这样的div:
<div class="slideshow" style="display:none"> <img src="image1.png"/> <img src="image2.png"/> <img src="image3.png"/> <img src="image4.png"/> <img src="image5.png"/> </div>
…然后,只要在.slideshow容器中,只要载入容器中的所有图像,就可以使用.load,而不管页面上的其他图像如何。
$('.slideshow img').load(function(){ $('.slideshow').show().slideshowPlugin(); });
(我放在一个显示器:没有一个例子,它会在加载时隐藏图像。)
更新(03.04.2013)自jQuery版本1.8以来,此方法已被弃用