图片预加载的JS代码

代码简介:

来自GOOGLE的图片预加载技术,也就是加载一个图片的时候,为了减轻网页的压力,将图片衰减后先显示出来,然后再慢慢加载,你就会看到一个图片由模糊突然变得清淅起来,这就是预加载的一种。这段代码就完成了图片的预加载功能,你可以点击一个小图然后看到大图慢慢变得清淅,直至加载完成。

代码内容:

View Code
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-

transitional.dtd"
>
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312" />
<title>图片预加载的JS代码 - www.webdm.cn</title>
<style type="text/css">
<!--
body
{background:#000; color:#FFFFFF;}
.big-img
{height: 390px; text-align:center;}
ol,ul
{list-style:none}
ul
{width: 632px; height: 56px; margin:10px auto;}
li
{float:left; width: 200px; height: 53px; margin-right:10px; }
ul li img
{ cursor:pointer}
-->
</style>
</head>

<body>
<div class="big-img"><img id="showImg" width="500" height="375" src="" alt="" /></div>
<ul id="imgList">
<li><img src="http://www.webdm.cn/images/wall5_s.jpg" /></li>
<li><img src="http://www.webdm.cn/images/wall6_s.jpg" /></li>
<li><img src="http://www.webdm.cn/images/wall7_s.jpg" /></li>
</ul>
<script type="text/javascript">
var imgL=document.getElementById("imgList").getElementsByTagName("img");
var imgURL="http://www.webdm.cn/images/";
var bigImg=new Array("wall5.jpg","wall6.jpg","wall7.jpg");
var imgshow=new Image();
for (var i = 0; i < imgL.length; i++) {
(
function() {
var p = i

imgL[i].onclick
= function() {
document.getElementById(
"showImg").src = this.src;
imgshow.src
= imgURL + bigImg[p];
imgshow.onload
= function() {
document.getElementById(
"showImg").src = this.src;
}
}
})()
}
</script>
</body>
</html>
<br />
<p><a href="http://www.webdm.cn">网页代码站</a> - 最专业的网页代码下载网站 - 致力为中国站长提供有质量的网页代码!

</p>

 

代码来自:http://www.webdm.cn/webcode/eea26d3a-1986-4ec1-98f0-b5656f31b80b.html

转载于:https://www.cnblogs.com/webdm/archive/2011/12/28/2304439.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值