找回密码
 入学

QQ登录

只需一步,快速开始

查看: 2419|回复: 0

仿淘宝首页banner焦点幻灯轮播代码无JQ,无通用样式

[复制链接]
发表于 2014-1-13 11:33:47 | 显示全部楼层 |阅读模式
主调用代码
  1. <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
  2. <html xmlns="http://www.w3.org/1999/xhtml">

  3. <head>
  4. <meta http-equiv="Content-Type" content="text/html; charset=gb2312">
  5. <title>仿淘宝首页banner焦点幻灯轮播代码</title>
  6. <link rel="stylesheet" type="text/css" href="plus/cpppt/cpppt.css" />
  7. <script type="text/javascript" src="plus/cpppt/cpppt.js"></script>
  8. </head>
  9. <div id="cppptbox">
  10.         <ul id="cppptlist">
  11.                 <li><a href="#" target="_blank"><img src="plus/cpppt/01.jpg" /></a></li>
  12.                 <li><a href="#" target="_blank"><img src="plus/cpppt/02.jpg" /></a></li>
  13.                 <li><a href="#" target="_blank"><img src="plus/cpppt/03.jpg" /></a></li>
  14.                 <li><a href="#" target="_blank"><img src="plus/cpppt/04.png" /></a></li>
  15.                 <li><a href="#" target="_blank"><img src="plus/cpppt/05.jpg" /></a></li>
  16.         </ul>
  17.         <ul id="cppptnum">
  18.                 <li class="cppptactive">1</li>
  19.                 <li>2</li>
  20.                 <li>3</li>
  21.                 <li>4</li>
  22.                 <li>5</li>
  23.         </ul>
  24. </div>
  25. </body>
  26. </html>
复制代码
样式表文件cpppt.css
  1. #cppptbox {width:490px; height:170px; background:#fff; margin:50px auto; position: relative; overflow: hidden;z-index:5000;}
  2. #cppptlist {position:absolute; left:0; top:0;margin:0; padding:0;}
  3. #cppptlist li {width:490px; height:170px; cursor: pointer; list-style: none;}
  4. #cppptlist img {border:0;}
  5. #cppptnum {position: absolute; right:10px; bottom:10px;margin:0; padding:0;}
  6. #cppptnum li {width:16px; height:16px; float:left; margin-right:2px; color:#fff; cursor: pointer; font-size: 12px; font-family:'Arial'; line-height:16px; text-align: center; border:1px solid #fff;list-style: none;}
  7. .cppptactive {background:#ff6600;}
复制代码
脚本文件cpppt.js
  1. window.onload=function()
  2. {
  3.         var dealy=3000;                                //time=3000ms
  4.         var oBox=document.getElementById('cppptbox');
  5.         var aList=document.getElementById('cppptlist');
  6.         var aNum=document.getElementById('cppptnum').getElementsByTagName('li');
  7.         var timer=null;
  8.         var now=0;
  9.         info();
  10.         for (var i=0; i<aNum.length; i++)
  11.         {
  12.                 aNum[i].index=i;
  13.                 aNum[i].onmouseover=function()
  14.                 {
  15.                         now=this.index;
  16.                         play(Running);
  17.                 }
  18.         }
  19.         function play(fn)
  20.         {
  21.                 for (var i=0; i<aNum.length; i++)
  22.                 {
  23.                         aNum[i].className='';
  24.                 }
  25.                 aNum[now].className='cppptactive';
  26.                 fn(aList,{top:-170*now});                       
  27.         }
  28.         function auto()
  29.         {
  30.                 clearInterval(timer);
  31.                 timer=setInterval(function()
  32.                 {
  33.                         now++;
  34.                         if(now==aNum.length)
  35.                         {
  36.                                 now=0;
  37.                         }
  38.                         play(Flexing);
  39.                 }, dealy);
  40.         }
  41.         auto();
  42.         oBox.onmouseover=function()
  43.         {
  44.                 clearInterval(timer);
  45.         }
  46.         oBox.onmouseout=function()
  47.         {
  48.                 auto();
  49.         }
  50. }
  51. //common
  52. function getClass(oParent,sClass)
  53. {
  54.         var value=[];
  55.         var Ele=oParent.getElementsByTagName('*');
  56.         for (var i=0; i<Ele.length; i++)
  57.         {
  58.                 var aClass=Ele[i].className.split(' ');
  59.                 for (n=0; n<aClass.length; n++)
  60.                 {
  61.                         if (aClass[n]==sClass)
  62.                         {
  63.                                 value.push(Ele[i]);
  64.                         }
  65.                 }
  66.         }
  67.         return value;
  68. }

  69. function getStyle(obj,name)
  70. {
  71.         if(obj.currentStyle)
  72.         {
  73.                 return obj.currentStyle[name];
  74.         }
  75.         else
  76.         {
  77.                 return getComputedStyle(obj,false)[name];
  78.         }
  79. }

  80. function setCSS3(obj,name,value)
  81. {
  82.         obj.style['webkit'+name.charAt(0).toUpperCase()+name.substring(1)]=value;
  83.         obj.style['moz'+name.charAt(0).toUpperCase()+name.substring(1)]=value;
  84.         obj.style['ms'+name.charAt(0).toUpperCase()+name.substring(1)]=value;
  85.         obj.style['O'+name.charAt(0).toUpperCase()+name.substring(1)]=value;
  86.         obj.style[name]=value;
  87. }

  88. function rnd(n)
  89. {
  90.         return Math.random()*2*n-n;
  91. }

  92. function Running(obj,json,fnEnd)
  93. {
  94.         clearInterval(obj.timer);
  95.         obj.timer=setInterval(function()
  96.         {
  97.                 var now=0;
  98.                 var bStop=true;
  99.                 for (var attr in json)
  100.                 {
  101.                         if(attr=='opacity')
  102.                         {
  103.                                 now=Math.round(parseFloat(getStyle(obj,attr))*100);
  104.                         }
  105.                         else
  106.                         {
  107.                                 now=parseInt(getStyle(obj,attr));
  108.                         }
  109.                         var speed=(json[attr]-now)/5;
  110.                         speed=speed>0?Math.ceil(speed):Math.floor(speed);
  111.                         if(now!=json[attr])bStop=false;
  112.                         if(attr=='opacity')
  113.                         {
  114.                                 obj.style.filter='alpha(opacity:'+now+speed+')';
  115.                                 obj.style.opacity=(now+speed)/100;
  116.                         }
  117.                         else
  118.                         {
  119.                                 obj.style[attr]=speed+now+'px';
  120.                         }
  121.                 }
  122.                 if(bStop)
  123.                 {
  124.                         clearInterval(obj.timer);
  125.                         if(fnEnd)fnEnd();
  126.                 }
  127.         }, 30);
  128. }

  129. function Flexing(obj,json,fnEnd)
  130. {
  131.         clearInterval(obj.timer);
  132.         obj.timer=setInterval(function()
  133.         {
  134.                 var now=0;
  135.                 var bStop=true;
  136.                 for (var attr in json)
  137.                 {
  138.                         if(!obj.speed)obj.speed={};
  139.                         if(!obj.speed[attr])obj.speed[attr]=0;
  140.                         now=parseInt(getStyle(obj,attr));
  141.                         if(Math.abs(json[attr]-now)>1 || Math.abs(obj.speed[attr])>1)
  142.                         {
  143.                                 bStop=false;
  144.                                 obj.speed[attr]+=(json[attr]-now)/5;
  145.                                 obj.speed[attr]*=0.85;
  146.                                 var MaxSpeed=50;
  147.                                 if(Math.abs(obj.speed[attr])>MaxSpeed)
  148.                                 {
  149.                                         obj.speed[attr]=obj.speed[attr]>0?MaxSpeed:-MaxSpeed;
  150.                                 }
  151.                                 obj.style[attr]=now+obj.speed[attr]+'px';
  152.                         }
  153.                 }
  154.                 if(bStop)
  155.                 {
  156.                         clearInterval(obj.timer);
  157.                         obj.style[attr]=json[attr]+'px';
  158.                         if(fnEnd)fnEnd();
  159.                 }
  160.         }, 30);
  161. }

  162. function convertStyle(obj)
  163. {
  164.         for (var i=0; i<obj.length; i++)
  165.         {
  166.                 obj[i].style.left=obj[i].offsetLeft+'px';
  167.                 obj[i].style.top=obj[i].offsetTop+'px';
  168.         }
  169.         for (var i=0; i<obj.length; i++)
  170.         {
  171.                 obj[i].style.position='absolute';
  172.                 obj[i].style.margin=0;
  173.         }
  174. }

  175. function info()
  176. {
  177.         var aLink=document.createElement('a');
  178.         var myinfo="";
  179.         aLink.innerHTML=myinfo;
  180.         aLink.onmouseover=function()
  181.         {
  182.                 aLink.style.textDecoration='underline';
  183.         }
  184.         aLink.onmouseout=function()
  185.         {
  186.                 aLink.style.textDecoration='none';
  187.         }
  188.         document.body.appendChild(aLink);
  189. }

  190. function create(oParent,Ele,num,sClass)
  191. {
  192.         var value=[];
  193.         var Element=0;
  194.         for (var i=0; i<num; i++)
  195.         {
  196.                 Element=document.createElement(Ele);
  197.                 oParent.appendChild(Element);
  198.                 if(sClass)Element.className=sClass;
  199.                 value.push(Element);       
  200.         }
  201.         return value;
  202. }

  203. function rndColor()
  204. {
  205.         var str=Math.ceil(Math.random()*0xFFFFFF).toString(16);
  206.         for (var i=0; i<str.length; i++)
  207.         {
  208.                 if(str.length<6)
  209.                 {
  210.                         str='0'+str;
  211.                 }
  212.         }
  213.         return str;
  214. }

  215. function shake(obj)
  216. {
  217.         var posData=[obj.offsetLeft,obj.offsetTop];
  218.         obj.onclick=function()
  219.         {
  220.                 var i=0;
  221.                 clearInterval(timer);
  222.                 var timer=setInterval(function()
  223.                 {
  224.                         i++;
  225.                         obj.style.left=posData[0]+((i%2)>0?-2:2)+'px';
  226.                         obj.style.top=posData[1]+((i%2)>0?-2:2)+'px';
  227.                         if(i>=30)
  228.                         {
  229.                                 clearInterval(timer);
  230.                                 obj.style.left=posData[0]+'px';
  231.                                 obj.style.top=posData[1]+'px';
  232.                         }
  233.                 }, 30);
  234.         }
  235. }
复制代码


本帖子中包含更多资源

您需要 登录 才可以下载或查看,没有账号?入学

×
您需要登录后才可以回帖 登录 | 入学

本版积分规则

QQ|Archiver|手机版|小黑屋|校园天空成立于2004年2月24日 ( 陕ICP备08000078号-8 )

GMT+8, 2025-5-11 02:15 , Processed in 0.127012 second(s), 21 queries .

Powered by Discuz! X3.5

© 2001-2025 Discuz! Team.

快速回复 返回顶部 返回列表