87,910
社区成员
发帖
与我相关
我的任务
分享
<!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>轻量封装图片轮动</title>
<script lanuage="javascript">
var ImgConvert = function (imgid, linkid) {
//构造参数
this.imgid = imgid;
this.linkid = linkid;
this.cursor = 0;
this.imgs = [];
};
ImgConvert.prototype = {
constructor : ImgConvert
, add : function (src, href) {
//缓存图片
return (this.imgs[this.imgs.length] = { obj : new Image, "href" : href }).obj.src = src;
}
, convert : function () {
//变化
var obj = this.imgs[this.cursor = this.cursor + 1 < this.imgs.length ? this.cursor + 1 : 0]
, img = document.getElementById(this.imgid);
if ('undefined' !== typeof img.style.filter) {
//如果不支持,就不用滤镜
img.style.filter = "blendTrans", img.filters(0).apply(), img.filters(0).play();
}
img.src = obj.obj.src, document.getElementById(this.linkid).href = obj.href;
}
, load : function () {
//初始化成员
var img = document.getElementById(this.imgid), i = 0, a = Array.prototype.slice.call(arguments, 0), t;
for (; i < a.length ; i ++) { t = a[i].split('|'), this.add(t[0], t[1]); }
}
};
var wc = new ImgConvert('img', 'link');
wc.load(
'http://www.google.cn/intl/zh-CN/images/logo_cn.gif|http://www.google.com/'
, 'http://www.baidu.com/img/logo.gif|http://www.baidu.com/'
, 'http://www.csdn.net/images/newcsdnlogo.gif|http://www.csdn.net/'
);
window.onload = function () { window.setInterval(function () { wc.convert(); }, 3000); };
</script>
</head>
<body>
<a id="link" href="http://www.google.com/" target="_blank">
<img id="img" src="http://www.google.cn/intl/zh-CN/images/logo_cn.gif" border="0" alt="" />
</a>
</body>
</html>