加快图片显示(JavaScript)

来源:互联网 发布:网络诈骗小品剧本7人 编辑:程序博客网 时间:2024/05/03 01:17
<script type="text/javascript"><!--google_ad_client = "pub-2947489232296736";/* 728x15, 创建于 08-4-23MSDN */google_ad_slot = "3624277373";google_ad_width = 728;google_ad_height = 15;//--></script><script type="text/javascript"src="http://pagead2.googlesyndication.com/pagead/show_ads.js"></script>
<script type="text/javascript"><!--google_ad_client = "pub-2947489232296736";/* 160x600, 创建于 08-4-23MSDN */google_ad_slot = "4367022601";google_ad_width = 160;google_ad_height = 600;//--></script><script type="text/javascript"src="http://pagead2.googlesyndication.com/pagead/show_ads.js"></script>
预先读取图片的方法是比较简单的,用javascript这样实现。
将如下的类似代码放在html的<head>区:
<script language="javascript">
<!--
image1= new image(100,50)
image1.src = "image1.gif"
image2 = new image(100,50)
image2.src = "image2.gif"
image3 = new image(100,50)
image3.src = "image3.gif"
// -->
</script>
这样浏览器在装载页面时就已经预先下载了3个图片
(image1.gif,images2.gif和image3.gif)。
当激发onmouseover事件时,浏览器直接从cache中读取图片,
速度当然快多了。
这里做一些小小说明:图片的名字可以是任意的,
100和50分别是读入cache的图片的宽度和高度。
但是脚本格式必须按照规定的格式写,"image1=new image"。
如果图片在其它服务器的子目录内,
只要用正确的绝对路径表示即可。


<<script type="text/javascript"><!--google_ad_client = "pub-2947489232296736";/* 728x15, 创建于 08-4-23MSDN */google_ad_slot = "3624277373";google_ad_width = 728;google_ad_height = 15;//--></script><script type="text/javascript"src="http://pagead2.googlesyndication.com/pagead/show_ads.js"></script>
<script type="text/javascript"><!--google_ad_client = "pub-2947489232296736";/* 160x600, 创建于 08-4-23MSDN */google_ad_slot = "4367022601";google_ad_width = 160;google_ad_height = 600;//--></script><script type="text/javascript"src="http://pagead2.googlesyndication.com/pagead/show_ads.js"></script>