当前位置:asp编程网>技术教程>Javascript教程>  正文

仿flash经典焦点图系列

1970-01-01 08:00:00   来源:蓝色理想    作者:佚名   浏览量:2722   收藏

折叠JavaScript Code复制内容到剪贴板
  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=utf-8" />   
  5. <base href="http://pigimg.zhongso.com/space/gallery/infoimgs/gc/gcqzj/" /><!--相对地址引用时记得删除这行!-->   
  6. <title>myFocus 1.0.0 BETA</title>   
  7. <style type="text/css">   
  8. body{background:#eee;padding:20px;}   
  9. /*=========mF_classicHC --经典怀旧系列一--========*/  
  10. .mF_classicHC .pic{border:1px solid #666;overflow:hidden;}   
  11. .mF_classicHC .pic li{position:absolute;left:1px;top:1px;}   
  12. .mF_classicHC .txt li{position:absolute;left:0;background:#dedede;overflow:hidden;}   
  13. .mF_classicHC .txt li a{display:block;color:#333;text-align:center;font-size:12px;font-weight:bold;text-decoration:none;}/*文字样式*/  
  14. .mF_classicHC .num,.mF_classicHC .num-bg{height:19px;position:absolute;z-index:3;right:0;bottom:31px;color:#fff;}/*按钮样式*/  
  15. .mF_classicHC .num-bg{width:100%;background:url(http://pigimg.zhongso.com/space/gallery/infoimgs/gc/gcqzj/20100907/2010090722133279907.png) right bottom no-repeat;_height:16px;_background:0;_filter:progid:DXImageTransform.Microsoft.AlphaImageLoader(src='http://pigimg.zhongso.com/space/gallery/infoimgs/gc/gcqzj/20100907/2010090722133279907.png', sizingMethod='scale');}   
  16. .mF_classicHC .num-bg li{position:absolute;}   
  17. .mF_classicHC .num li{float:left;width:26px;height:16px;line-height:16px;padding-top:3px;text-align:center;cursor:pointer;position:relative;}   
  18. .mF_classicHC .num li span{position:absolute;top:3px;left:0;width:1px;height:16px;overflow:hidden;background:#DADADA;}   
  19. .mF_classicHC .num li.current,.mF_classicHC .num li.hover{background:url(http://pigimg.zhongso.com/space/gallery/infoimgs/gc/gcqzj/20100901/2010090111470535358.gif) left top no-repeat;}/*当前/悬停按钮样式*/   
  20. .mF_classicHC .num li.hover{background-position:right bottom;}   
  21. </style>   
  22. <script type="text/javascript">   
  23. /*  
  24.  * myFocus焦点图基本库代码开始  
  25.  */  
  26. var myFocus={   
  27.     //myFocus JavaScript Library v1.0.0 beta   
  28.     //Design By Koen @ 2010.9.16   
  29.     //http://hi.baidu.com/koen_li   
  30.     $:function(id){return document.getElementById(id);},   
  31.     $$:function(tag,obj){return (typeof obj=='object'?obj:this.$(obj)).getElementsByTagName(tag);},   
  32.     $li:function(obj,n){return this.$$('li',this.$$('ul',obj)[n])},   
  33.     linear:function(t,b,c,d){return c*t/d + b;},   
  34.     easeIn:function(t,b,c,d){return c*(t/=d)*t*t*t + b;},   
  35.     easeOut:function(t,b,c,d){return -c*((t=t/d-1)*t*t*t - 1) + b;},   
  36.     easeInOut:function(t,b,c,d){return ((t/=d/2) < 1)?(c/2*t*t*t*t + b):(-c/2*((t-=2)*t*t*t - 2) + b);},   
  37.     style:function(obj,style){return (+[1,])?window.getComputedStyle(obj,null)[style]:obj.currentStyle[style];},//getStyle简化版   
  38.     opa:function(obj,v){//取得或设置对象透明度,默认100   
  39.         if(v!=undefined) {v=v>100?100:(v<0?0:v); obj.style.filter = "alpha(opacity=" + v + ")"; obj.style.opacity = (v / 100);}   
  40.         else return (!+[1,])?((obj.filters.alpha)?obj.filters.alpha.opacity:100):((obj.style.opacity)?obj.style.opacity*100:100);   
  41.     },   
  42.     animate:function(obj,prop,val,spd,type,fn){   
  43.         var opa=prop=='opacity'?true:false;   
  44.         if(opa&&obj.style.display=='none'){obj.style.display='';this.opa(obj,0);}   
  45.         var t=0,b=opa?this.opa(obj):parseInt(this.style(obj,prop)),c=val-b,d=spd||50,st=type||'easeOut',m=c>0?'ceil':'floor';   
  46.         if(obj[prop+'Timer']) clearInterval(obj[prop+'Timer']);   
  47.         obj[prop+'Timer']=setInterval(function(){   
  48.             if(opa&&t<d){myFocus.opa(obj,Math[m](myFocus[st](++t,b,c,d)));}   
  49.             else if(!opa&&t<d){obj.style[prop]=Math[m](myFocus[st](++t,b,c,d))+'px';}   
  50.             else {if(opa&&val==0){obj.style.display='none'}clearInterval(obj[prop+'Timer']);fn&&fn.call(obj);}   
  51.         },10);return this;   
  52.     },   
  53.     fadeIn:function(obj,speed,fn){this.animate(obj,'opacity',100,speed==undefined?20:speed,'linear',fn);return this;},   
  54.     fadeOut:function(obj,speed,fn){this.animate(obj,'opacity',0,speed==undefined?20:speed,'linear',fn);return this;},   
  55.     slide:function(obj,params,speed,easing,fn){for(var p in params) this.animate(obj,p,params[p],speed,easing,fn);return this;},   
  56.     stop:function(obj){//停止所有运动函数   
  57.         var animate=['left','right','top','bottom','width','height','opacity'];   
  58.         for(var i=0;i<animate.length;i++) if(obj[animate[i]+'Timer']) clearInterval(obj[animate[i]+'Timer']);   
  59.         return this;   
  60.     },   
  61.     initCSS:function(p){   
  62.         var css=[],oStyle = document.createElement('style');oStyle.type='text/css';   
  63.         if(p.width){css.push('.'+p.style+' *{margin:0;padding:0;border:0;list-style:none;}.'+p.style+'{position:relative;width:'+p.width+'px;height:'+p.height+'px;overflow:hidden;font:12px/1.5 Verdana,Geneva,sans-serif;background:#fff;}.'+p.style+' .loading{position:absolute;z-index:9999;width:100%;height:100%;color:#666;text-align:center;padding-top:'+0.3*p.height+'px;background:#fff url(http://nethd.zhongsou.com/wtimg/i_41956/28236-loading.gif) center '+0.4*p.height+'px no-repeat;}.'+p.style+' .pic,.'+p.style+' .pic *{width:'+p.width+'px;height:'+p.height+'px;}.'+p.style+' .txt li,.'+p.style+' .txt li span,.'+p.style+' .txt-bg{width:'+p.width+'px;height:'+p.txtHeight+'px;line-height:'+p.txtHeight+'px;overflow:hidden;}')}   
  64.         if(oStyle.styleSheet){oStyle.styleSheet.cssText=css.join('');} else {oStyle.innerHTML=css.join('');}   
  65.         var oHead = this.$$('head',document)[0];oHead.insertBefore(oStyle,oHead.firstChild);   
  66.     },   
  67.     setting:function(par){   
  68.         if(window.attachEvent){(function(){try{myFocus.$(par.id).className=par.style;myFocus.initCSS(par);}catch(e){setTimeout(arguments.callee,0);}})();window.attachEvent('onload',function(){myFocus[par.style](par)});}   
  69.         else{document.addEventListener("DOMContentLoaded",function(){myFocus.$(par.id).className=par.style;myFocus.initCSS(par);},false);window.addEventListener('load',function(){myFocus[par.style](par)},false);}   
  70.     },   
  71.     addList:function(obj,cla){//生成HMTL,cla为生成列表的class,其中封装有:cla='txt'(生成alt文字),cla='num'(生成按钮数字),cla='thumb'(生成小图)   
  72.         var s=[],n=this.$li(obj,0).length,num=cla.length;   
  73.         for(var j=0;j<num;j++){   
  74.             s.push('<ul class='+cla[j]+'>');   
  75.             for(var i=0;i<n;i++){s.push('<li>'+(cla[j]=='num'?('<a>'+(i+1)+'</a>'):(cla[j]=='txt'?this.$li(obj,0)[i].innerHTML.replace(/\>(.|\n|\r)*?(\<\/a\>)/i,'>'+(this.$$('img',obj)[i]?this.$$('img',obj)[i].alt:'')+'</a>'):(cla[j]=='thumb'?'<img src='+(this.$$('img',obj)[i].getAttribute("thumb")||this.$$('img',obj)[i].src)+' />':'')))+'<span></span></li>')};   
  76.             s.push('</ul>');   
  77.         }; obj.innerHTML+=s.join('');   
  78.     },   
  79.     switchMF:function(fn1,fn2,auto){   
  80.         return "box.removeChild(this.$$('div',box)[0]);var run=function(idx){("+fn1+")();if (index == n - 1) index = -1;var next = idx != undefined ? idx: index + 1;("+fn2+")();index=next;};run(index);if("+auto+"!==false) var auto=setInterval(function(){run()},t);box.onmouseover=function(){if(auto) clearInterval(auto);};box.onmouseout=function(){if(auto) auto=setInterval(function(){run()},t);}"  
  81.     },   
  82.     bind:function(arrStr,type,delay){   
  83.         return "for (var j=0;j<n;j++){"+arrStr+"[j].index=j;if("+type+"=='click'){"+arrStr+"[j].onmouseover=function(){if(this.className!='current') this.className='hover'};"+arrStr+"[j].onmouseout=function(){if(this.className=='hover') this.className=''};"+arrStr+"[j].onclick=function(){if(this.index!=index) run(this.index)};}else if("+type+"=='mouseover'){"+arrStr+"[j].onmouseover=function(){var self=this;if("+delay+"==0){if(!self.className) run(self.index)}else "+arrStr+".d=setTimeout(function(){if(!self.className) run(self.index)},"+(delay==undefined?100:delay)+")};"+arrStr+"[j].onmouseout=function(){clearTimeout("+arrStr+".d)};}else{alert('myFocus 不支持这样的事件 \"'+"+type+"+'\"');break;}}"  
  84.     },   
  85.     extend:function(fnObj){for(var p in fnObj) this[p]=fnObj[p];}   
  86. }   
  87. /*  
  88.  * myFocus焦点图基本库代码结束  
  89.  * 下面是各款基于myFocus库制作的焦点图风格皮肤,可自行按需选择  
  90.  * myFocus焦点图库及皮肤可自由使用,保留作者相关信息即可,谢谢支持!^^  
  91.  */  
  92. myFocus.extend({   
  93.     mF_classicHC:function(par){//*************经典怀旧系列一--慧聪风格*********   
  94.         var box=this.$(par.id);//定义焦点图盒子   
  95.         this.addList(box,['txt','num-bg','num']);//添加ul列表   
  96.         var pic=this.$li(box,0),txt=this.$li(box,1),num=this.$li(box,3);//定义焦点图元素   
  97.         var index=0,n=pic.length,t=par.time*1000;//运行时相关参数   
  98.         //CSS   
  99.         var txtH=par.txtHeight;   
  100.         box.style.width=par.width+2+'px';box.style.height=par.height+txtH+2+'px';   
  101.         this.$$('ul',box)[2].style.bottom=this.$$('ul',box)[3].style.bottom=txtH+1+'px';   
  102.         for(var i=0;i<n;i++){   
  103.             pic[i].style.display='none';txt[i].style.display='none';   
  104.             txt[i].style.top=par.height+2+'px';txt[i].style.width=par.width+2+'px';   
  105.         }   
  106.         //PLAY   
  107.         eval(this.switchMF(function(){   
  108.             pic[index].style.display='none';   
  109.             txt[index].style.display='none';   
  110.             num[index].className='';   
  111.         },function(){   
  112.             myFocus.fadeIn(pic[next]);   
  113.             txt[next].style.display='';   
  114.             num[next].className='current';   
  115.         }))   
  116.         eval(this.bind('num','par.trigger',par.delay));   
  117.     }   
  118. })   
  119. //下面为焦点图的调用,可在网页任意位置调用   
  120. myFocus.setting({   
  121.     style:'mF_classicHC',//风格样式   
  122.     id:'myFocus',//焦点图ID   
  123.     trigger:'click',//按钮切换模式:'click'(点击触发)/'mouseover'(悬停触发,默认有0.1秒延迟,可以自行添加参数'delay:毫秒'设置)   
  124.     time:4,//切换图片的时间间隔,单位秒   
  125.     txtHeight:26,//文字层高,26为推荐,0为隐藏   
  126.     width:380,//宽(大图),注意:整个焦点图的宽等于或大于图片宽   
  127.     height:246//高(大图),注意同上   
  128. });   
  129. </script>   
  130. </head>   
  131. <body>   
  132. <div id="myFocus">   
  133.     <div class="loading"><span>请稍候...</span></div><!--载入画面-->   
  134.     <ul class="pic"><!--内容列表-->   
  135.         <li><a href="#"><img src="20100510/2010051018042735524.jpg" thumb="" alt="图片1来源于网络,版权属于作者" text="" /></a></li>   
  136.         <li><a href="#"><img src="20100510/2010051018044355191.jpg" thumb="" alt="版权属于作者,图片2来源于网络" text="" /></a></li>   
  137.         <li><a href="#"><img src="20100510/2010051018050315609.jpg" thumb="" alt="图片3来源于网络,版权属于作者" text="" /></a></li>   
  138.         <li><a href="#"><img src="20100510/2010051018052886494.jpg" thumb="" alt="版权属于作者,图片4来源于网络" text="" /></a></li>   
  139.     </ul>   
  140. </div>   
  141. </body>   
  142. </html>  

 


提示:可以修改后运行.
 

 



关于我们-广告合作-联系我们-积分规则-网站地图

Copyright(C)2013-2017版权所属asp编程网