热门:网页模板.net视频教程JQueryMVCjsonExtJs源码示例三级联动JQuery菜单
您现在的位置:.Net中文社区>> 实用代码>>正文内容

仿QQ首页图片轮换效果

发布时间:2010年03月12日点击数: 佚名

先看一下效果图:

直接复制如下代码运行可以看到效果:

  1. <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3c.org/TR/1999/REC-html401-19991224/loose.dtd"> 
  2. <HTML xmlns="http://www.w3.org/1999/xhtml"> 
  3. <HEAD> 
  4. <TITLE>腾讯软件--图片滑动</TITLE> 
  5. <style>  
  6. BODY { 
  7.     PADDING-BOTTOM: 0px; MARGIN: 0px; PADDING-LEFT: 0px; PADDING-RIGHT: 0px; PADDING-TOP: 0px 
  8. UL { 
  9.     PADDING-BOTTOM: 0px; MARGIN: 0px; PADDING-LEFT: 0px; PADDING-RIGHT: 0px; PADDING-TOP: 0px 
  10. .container { 
  11.     WIDTH: 610px; HEIGHT: 205px 
  12. .container A IMG { 
  13.     WIDTH: 610px; HEIGHT: 205px 
  14. .container IMG { 
  15.     BORDER-BOTTOM-STYLE: none; BORDER-RIGHT-STYLE: none; BORDER-TOP-STYLE: none; BORDER-LEFT-STYLE: none 
  16. .td_f A IMG { 
  17.     PADDING-BOTTOM: 0px; MARGIN: 0px; PADDING-LEFT: 0px; PADDING-RIGHT: 0px; PADDING-TOP: 0px 
  18. .num { 
  19.     POSITION: absolute; WIDTH: 90px; FLOAT: right; TOP: 180px; LEFT: 520px 
  20. .num LI { 
  21.     TEXT-ALIGN: center; LINE-HEIGHT: 15px; LIST-STYLE-TYPE: none; MARGIN: 1px; WIDTH: 15px; FONT-FAMILY: Arial; BACKGROUND: url(http://www.aspxcs.net/UploadFiles/2010/3/201003122330190201.gif) no-repeat -15px 0px; FLOAT: left; HEIGHT: 15px; COLOR: #86a2b8; FONT-SIZE: 12px; CURSOR: pointer 
  22. .num LI.on { 
  23.     LINE-HEIGHT: 15px; WIDTH: 15px; BACKGROUND: url(http://www.aspxcs.net/UploadFiles/2010/3/201003122330190201.gif) no-repeat; HEIGHT: 15px; COLOR: #ffffff 
  24. .more { 
  25.     FLOAT: right 
  26. .more1 A { 
  27.     TEXT-ALIGN: left; LINE-HEIGHT: 25px; MARGIN: 0px 0px 0px 10px; COLOR: #3373a3 
  28. </style> 
  29. <SCRIPT language=javascript> 
  30.         if(typeof(pgvMain) == 'function') 
  31.                 pgvMain(); 
  32. </SCRIPT> 
  33. <SCRIPT> 
  34. var gtopTab="one"
  35. function $id(id){ 
  36.     return document.getElementById(id);  
  37. function changesTab(tab_id){ 
  38.     if (tab_id==gtopTab){ 
  39.         return;  
  40.     }else{ 
  41.         $id(gtopTab).className="unselect";   
  42.         $id(tab_id).className="select"
  43.         $id("tab_"+gtopTab).style.display="none"
  44.         $id("tab_"+tab_id).style.display="block"
  45.         gtopTab=tab_id
  46.     } 
  47. </SCRIPT> 
  48. <SCRIPT type=text/javascript> 
  49. var $ = function (id) { 
  50.     return "string" == typeof id ? document.getElementById(id) : id; 
  51. }; 
  52. var Extend = function(destination, source) { 
  53.     for (var property in source) { 
  54.         destination[property] = source[property]; 
  55.     } 
  56.     return destination; 
  57. var CurrentStyle = function(element){ 
  58.     return element.currentStyle || document.defaultView.getComputedStyle(element, null); 
  59. var Bind = function(object, fun) { 
  60.     var args = Array.prototype.slice.call(arguments).slice(2); 
  61.     return function() { 
  62.         return fun.apply(object, args.concat(Array.prototype.slice.call(arguments))); 
  63.     } 
  64. var Tween = { 
  65.     Quart: { 
  66.         easeOut: function(t,b,c,d){ 
  67.             return -c * ((tt=t/d-1)*t*t*t - 1) + b; 
  68.         } 
  69.     }, 
  70.     Back: { 
  71.         easeOut: function(t,b,c,d,s){ 
  72.             if (s == undefined) s = 1.70158; 
  73.             return c*((tt=t/d-1)*t*((s+1)*t + s) + 1) + b; 
  74.         } 
  75.     }, 
  76.     Bounce: { 
  77.         easeOut: function(t,b,c,d){ 
  78.             if ((t/=d) < (1/2.75)) { 
  79.                 return c*(7.5625*t*t) + b; 
  80.             } else if (t < (2/2.75)) { 
  81.                 return c*(7.5625*(t-=(1.5/2.75))*t + .75) + b; 
  82.             } else if (t < (2.5/2.75)) { 
  83.                 return c*(7.5625*(t-=(2.25/2.75))*t + .9375) + b; 
  84.             } else { 
  85.                 return c*(7.5625*(t-=(2.625/2.75))*t + .984375) + b; 
  86.             } 
  87.         } 
  88.     } 
  89. //容器对象,滑动对象,切换数量 
  90. var SlideTrans = function(container, slider, count, options) { 
  91.     this._slider = $(slider); 
  92.     this._container = $(container);//容器对象 
  93.     this._timer = null;//定时器 
  94.     this._count = Math.abs(count);//切换数量 
  95.     this._target = 0;//目标值 
  96.     thisthis._t = this._b = this._c = 0;//tween参数 
  97.      
  98.     this.Index = 0;//当前索引 
  99.      
  100.     this.SetOptions(options); 
  101.      
  102.     this.Auto = !!this.options.Auto; 
  103.     this.Duration = Math.abs(this.options.Duration); 
  104.     this.Time = Math.abs(this.options.Time); 
  105.     this.Pause = Math.abs(this.options.Pause); 
  106.     thisthis.Tween = this.options.Tween; 
  107.     thisthis.onStart = this.options.onStart; 
  108.     thisthis.onFinish = this.options.onFinish; 
  109.      
  110.     var bVertical = !!this.options.Vertical; 
  111.     this._css = bVertical ? "top" : "left";//方向 
  112.      
  113.     //样式设置 
  114.     var p = CurrentStyle(this._container).position; 
  115.     p == "relative" || p == "absolute" || (this._container.style.position = "relative"); 
  116.     this._container.style.overflow = "hidden"
  117.     this._slider.style.position = "absolute"
  118.      
  119.     thisthis.Change = this.options.Change ? this.options.Change : 
  120.         this._slider[bVertical ? "offsetHeight" : "offsetWidth"] / this._count; 
  121. }; 
  122. SlideTrans.prototype = { 
  123.   //设置默认属性 
  124.   SetOptions: function(options) { 
  125.     this.options = {//默认值 
  126.         Vertical:   true,//是否垂直方向(方向不能改) 
  127.         Auto:       true,//是否自动 
  128.         Change:     0,//改变量 
  129.         Duration:   50,//滑动持续时间 
  130.         Time:       10,//滑动延时 
  131.         Pause:      4000,//停顿时间(Auto为true时有效) 
  132.         onStart:    function(){},//开始转换时执行 
  133.         onFinish:   function(){},//完成转换时执行 
  134.         Tween:      Tween.Quart.easeOut//tween算子 
  135.     }; 
  136.     Extend(this.options, options || {}); 
  137.   }, 
  138.   //开始切换 
  139.   Run: function(index) { 
  140.     //修正index 
  141.     index == undefined && (index = this.Index); 
  142.     index < 0 && (index = this._count - 1) || index >= this._count && (index = 0); 
  143.     //设置参数 
  144.     this._target = -Math.abs(this.Change) * (this.Index = index); 
  145.     this._t = 0
  146.     this._b = parseInt(CurrentStyle(this._slider)[this.options.Vertical ? "top" : "left"]); 
  147.     thisthis._c = this._target - this._b; 
  148.      
  149.     this.onStart(); 
  150.     this.Move(); 
  151.   }, 
  152.   //移动 
  153.   Move: function() { 
  154.     clearTimeout(this._timer); 
  155.     //未到达目标继续移动否则进行下一次滑动 
  156.     if (this._c && this._t < this.Duration) { 
  157.         this.MoveTo(Math.round(this.Tween(this._t++, this._b, this._c, this.Duration))); 
  158.         this._timer = setTimeout(Bind(this, this.Move), this.Time); 
  159.     }else{ 
  160.         this.MoveTo(this._target); 
  161.         this.Auto && (this._timer = setTimeout(Bind(this, this.Next), this.Pause)); 
  162.     } 
  163.   }, 
  164.   //移动到 
  165.   MoveTo: function(i) { 
  166.     this._slider.style[this._css] = i + "px"; 
  167.   }, 
  168.   //下一个 
  169.   Next: function() { 
  170.     this.Run(++this.Index); 
  171.   }, 
  172.   //上一个 
  173.   Previous: function() { 
  174.     this.Run(--this.Index); 
  175.   }, 
  176.   //停止 
  177.   Stop: function() { 
  178.     clearTimeout(this._timer); this.MoveTo(this._target); 
  179.   } 
  180. }; 
  181. </SCRIPT> 
  182. <BODY> 
  183. <DIV id=idContainer2 class=container> 
  184. <TABLE id=idSlider2 border=0 cellSpacing=0 cellPadding=0> 
  185.   <TBODY> 
  186. <TR> 
  187.  <td class="td_f"><a href="" onclick="pgvSendClick({hottag:'ISD.SHOW.BANNER.PY'});"><img src="http://www.aspxcs.net/UploadFiles/2010/3/201003122258434719.jpg" /></a></td> 
  188.         <td class="td_f"><a href="" onclick="pgvSendClick({hottag:'ISD.SHOW.BANNER.PLAYER'});"><img src="http://www.aspxcs.net/UploadFiles/2010/3/201003122258445123.jpg" /></a></td> 
  189.         <td class="td_f"><a href="" onclick="pgvSendClick({hottag:'ISD.SHOW.BANNER.XF'});"><img src="http://www.aspxcs.net/UploadFiles/2010/3/201003122258452471.jpg" /></a></td> 
  190.         <td class="td_f"><a href="" onclick="pgvSendClick({hottag:'ISD.SHOW.BANNER.TT'});"><img src="http://www.aspxcs.net/UploadFiles/2010/3/201003122258468980.jpg" /></a></td> 
  191. </TR> 
  192.   </TBODY> 
  193. </TABLE> 
  194. <UL id=idNum class=num></UL> 
  195. </DIV> 
  196. <SCRIPT> 
  197. //new SlideTrans("idContainer", "idSlider", 3).Run(); 
  198. /////////////////////////////////////////////////////////// 
  199. var forEach = function(array, callback, thisObject){ 
  200.     if(array.forEach){ 
  201.         array.forEach(callback, thisObject); 
  202.     }else{ 
  203.         for (var i = 0len = array.length; i < len; i++) { callback.call(thisObject, array[i], i, array); } 
  204.     } 
  205. var st = new SlideTrans("idContainer2", "idSlider2", 5, { Vertical: false }); 
  206. var nums = []; 
  207. //插入数字 
  208. for(var i = 0n = st._count - 1; i <= n;){ 
  209.     (nums[i] = $("idNum").appendChild(document.createElement("li"))).innerHTML = ++i; 
  210. forEach(nums, function(o, i){ 
  211.     o.onmouseover = function(){ o.className = "on"st.Auto = false; st.Run(i); } 
  212.     o.onmouseout = function(){ o.className = ""st.Auto = true; st.Run(); } 
  213. }) 
  214. //设置按钮样式 
  215. st.onStart = function(){ 
  216.     forEach(nums, function(o, i){ o.className = st.Index == i ? "on" : ""; }) 
  217. //$("idAuto").onclick = function(){ 
  218.     //if(st.Auto){ 
  219.         //st.Auto = false; st.Stop(); this.value = "自动"
  220.     //}else{ 
  221.         //st.Auto = true; st.Run(); this.value = "停止"
  222.     //} 
  223. //} 
  224. //$("idNext").onclick = function(){ st.Next(); } 
  225. //$("idPre").onclick = function(){ st.Previous(); } 
  226. //$("idTween").onchange = function(){ 
  227.     //switch (parseInt(this.value)){ 
  228.         //case 2 : 
  229.             //st.Tween = Tween.Bounce.easeOut; break; 
  230.         //case 1 : 
  231.             //st.Tween = Tween.Back.easeOut; break; 
  232.         //default : 
  233.             //st.Tween = Tween.Quart.easeOut; 
  234.     //} 
  235. //} 
  236. st.Run(); 
  237. </SCRIPT> 
  238. </BODY></HTML> 

本站热点业务

更多模板/案例展示

关于我们 | 联系我们 | 团队日志 | 网站地图 | 网站合作