JS旋转图片阵效果 - 已封装,兼容IE,FF,OP,GG
- 作者:takuma888 来源:蓝色理想 文章点击数:
<!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旋转图片阵效果 brought to you by 斩梦人.天天 qq:22062019</title>
<style type="text/css">
body{background:black;color:white;font-family: Arial, Helvetica, sans-serif;font-size:16px;line-height:29px}
span{border:1px solid gray;background:#333;padding:4px;font-weight:bold;}
</style></head>
<body>
<span>使用方法</span>:<br>
首先定义一个imgRound类:<br>
<span>var rt = new imgRound("imgContainer", 120, 90, 500, 220, 230, 0.01)</span><br>
然后使用定时函数调用imgRound实例的roundMove方法:<br>
<span>setInterval(function(){rt.roundMove()}, 20)</span><br>
<script>
window.onload=function(){
var rt=new imgRound("imgContainer",120,90,300,80,230,0.01);
setInterval(function(){rt.roundMove()},20)
}
function imgRound(id,w,h,x,y,r,dv,rh,ah){
if (ah==undefined) ah=1;
if (rh==undefined) rh=10;
var dv=dv*ah; //旋转速度
var pi=3.1415926575;
var d=pi/2;
var pd=Math.asin(w/2/r);
var smove=true;
var imgArr=new Array();
var objectId=id;
var o=document.getElementById(objectId);
o.style.position="relative";
var arrimg=o.getElementsByTagName("img");
var pn=arrimg.length; //图片数量
var ed=pi*2/pn;
for (n=0;n<arrimg.length;n++){
var lk=arrimg[n].getAttribute("link");
if (lk!=null) arrimg[n].setAttribute("title",lk)
arrimg[n].onclick=function(){
if (this.getAttribute("link")!=null){
if (this.getAttribute("target")!="_blank") window.location=(this.getAttribute("link"))
else window.open(this.getAttribute("link"))
}
}
arrimg[n].onmouseout=function(){smove=true;}
arrimg[n].onmouseover=function(){smove=false;}
arrimg[n].style.position="absolute";
imgArr.push(arrimg[n]);
}
this.roundMove=function(){
for (n=0;n<=pn-1;n++){
var o=imgArr[n];
var ta=Math.sin(d+ed*n),strFilter;
if (ta<0) o.style.left=Math.cos(d+ed*n-pd)*r+x+"px";
else o.style.left=Math.cos(d+ed*n+pd)*r+x+"px";
o.style.top=ta*rh+rh+y+"px";
var zoom=Math.abs(Math.sin((d+ed*n)/2+pi/4))*0.5+0.5;
o.style.width=Math.abs(Math.cos(d+ed*n+pd)-Math.cos(d+ed*n-pd))*zoom*r+"px";
o.style.height=zoom*h+"px";
if (ta<0) {ta=(ta+1)*80+20;o.style.zIndex=0;}
else {ta=100;o.style.zIndex=1}
if (o.style.zIndex<=0) strFilter="FlipH(enabled:true)"
else strFilter="FlipH(enabled:false)";
strFilter=strFilter+" alpha(opacity="+ta+")";
o.style.opacity=ta/100;
o.style.filter=strFilter;
}
if (smove) d=d+dv;
}
}
</script>
<div id="imgContainer" style="width:600px;height:300px;border:1px solid red">
<img src="/Upfiles/BeyondPic/2008-09/20089299277319901.jpg"/>
<img src="/Upfiles/BeyondPic/2008-09/20089296987918185.jpg"/>
<img src="/Upfiles/BeyondPic/2008-09/20089293125661279.jpg"/>
<img src="/Upfiles/BeyondPic/2008-09/20089297498408728.jpg" link="http://www.baidu.com" target="_blank"/>
<img src="/Upfiles/BeyondPic/2008-09/20089294259920091.jpg" link="http://www.google.com"/>
<img src="/Upfiles/BeyondPic/2008-09/20089299277319901.jpg"/>
<img src="/Upfiles/BeyondPic/2008-09/20089296987918185.jpg"/>
<img src="/Upfiles/BeyondPic/2008-09/20089293125661279.jpg"/>
</div>
参数说明: initRound(id,w,h,x,y,r,dv,rh,ah);<br>
id: 容器ID<br>
w: 图片宽度<br>
h: 图片高度<br>
x: 圆心水平位置<br>
y: 圆心垂直位置<br>
r: 圆圈半径<br>
dv: 旋转速度<br>
rh: 垂直距离 (可选,默认为10)<br>
ah: 旋转方向 (可选,1:顺时针,2:逆时针,默认为1)<br>
<body></html>

- 上一篇:添加了行为的CSS星级选择器
- 下一篇:刷新不变化树形菜单
- 相关文章
| ·关于js和css在IE与FF下的一些杂记 | 10-21 |
| ·AS3与JS交互的问题 | 10-21 |
| ·刷新不变化树形菜单 | 10-21 |
| ·添加了行为的CSS星级选择器 | 09-29 |
| ·风无双兼容IE6 IE7 FF的显示隐藏菜单测试版 | 09-22 |
| ·EDrag 拖曳层类 v1.0 | 09-22 |
| ·再发适合各种浏览器的拖动层 | 09-15 |
| ·一个弹出层的JS特效 | 09-05 |
