这里有新鲜出炉的 Javascript 教程,程序狗速度看过来!
Javascript 是一种由 Netscape 的 LiveScript 发展而来的原型化继承的基于对象的动态类型的区分大小写的客户端脚本语言,主要目的是为了解决服务器端语言,比如 Perl,遗留的速度问题,为客户提供更流畅的浏览效果。
非常漂亮的旋转图片陈效果代码,已封装成类,方便调用
- <!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>
- 使用方法:
- 首先定义一个imgRound类:
- var rt = new imgRound("imgContainer", 120, 90, 500, 220, 230, 0.01)
- 然后使用定时函数调用imgRound实例的roundMove方法:
- setInterval(function(){rt.roundMove()}, 20)
- <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>
- <img class="img-responsive" src="http://www.lululu520.cn/blueidea/images/s1.jpg" data-src=""/>
- <img class="img-responsive" src="http://www.lululu520.cn/blueidea/images/s2.jpg" data-src=""/>
- <img class="img-responsive" src="http://www.lululu520.cn/blueidea/images/s3.jpg" data-src=""/>
- <img class="img-responsive" src="http://www.lululu520.cn/blueidea/images/s4.jpg" link="http://www.baidu.com" target="_blank" data-src=""/>
- <img class="img-responsive" src="http://www.lululu520.cn/blueidea/images/s5.jpg" link="http://www.google.com" data-src=""/>
- <img class="img-responsive" src="http://www.lululu520.cn/blueidea/images/s1.jpg" data-src=""/>
- <img class="img-responsive" src="http://www.lululu520.cn/blueidea/images/s2.jpg" data-src=""/>
- <img class="img-responsive" src="http://www.lululu520.cn/blueidea/images/s3.jpg" data-src=""/>
- </div>
- 参数说明: initRound(id,w,h,x,y,r,dv,rh,ah);
- id: 容器ID
- w: 图片宽度
- h: 图片高度
- x: 圆心水平位置
- y: 圆心垂直位置
- r: 圆圈半径
- dv: 旋转速度
- rh: 垂直距离 (可选,默认为10)
- ah: 旋转方向 (可选,1:顺时针,2:逆时针,默认为1)
- <body></html>
(adsbygoogle = window.adsbygoogle || []).push({});
来源: http://www.phperz.com/article/17/0701/287897.html