免费注册 查看新帖 |

Chinaunix

  平台 论坛 博客 文库
最近访问板块 发新帖
查看: 2242 | 回复: 0
打印 上一主题 下一主题

jQuery 仿flash的广告轮播 [复制链接]

论坛徽章:
0
跳转到指定楼层
1 [收藏(0)] [报告]
发表于 2010-11-08 16:57 |只看该作者 |倒序浏览
来自:花见花开

很多网站的首页都有广告轮播,今天闲来看了一网站的首页广告轮播方式,是通过 jQuery的blockSlide插件实现的,然后自己测试了一下,很好。

整个页面如下:

  1. <%@ Page Language="C#" AutoEventWireup="true" CodeFile="Test.aspx.cs" Inherits="Test" %>

  2. <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
  3. <html xmlns="http://www.w3.org/1999/xhtml">
  4. <head runat="server">
  5.     <title></title>
  6.     <script src="Scripts/jquery-1.4.1-vsdoc.js" type="text/javascript"></script>
  7.     <script src="_Template/js/blockSlide.js" type="text/javascript"></script>
  8.     <style type="text/css">
  9.         div#imgADPlayer
  10.         {
  11.             margin: auto;
  12.             margin-bottom: 4px;
  13.             width: 960px;
  14.             height: 120px;
  15.             background: url(../images/photo_01.jpg) left top no-repeat;
  16.             padding: 0px;
  17.             border: none;
  18.             clear: both;
  19.             position: relative;
  20.         }
  21.         
  22.         div#imgADPlayer .smask
  23.         {
  24.             position: absolute;
  25.             left: 0px;
  26.             top: 0px;
  27.         }
  28.     </style>
  29. </head>
  30. <body>
  31.     <!-- 滚动图片开始 -->
  32.     <div id="imgADPlayer">
  33.         <div id="AdTop">
  34.             <div id="myjQueryContent">
  35.                 <div>
  36.                     <a href="javascript:void(0)">
  37.                         <img src="_Template/images/photo_01.jpg" alt="" /></a></div>
  38.                 <div class="smask">
  39.                     <a href="javascript:void(0)">
  40.                         <img src="_Template/images/photo_02.jpg" alt="" /></a></div>
  41.                 <div class="smask">
  42.                     <a href="javascript:void(0)">
  43.                         <img src="_Template/images/photo_03.jpg" alt="" /></a>
  44.                 </div>
  45.                 <div class="smask">
  46.                     <a href="javascript:void(0)">
  47.                         <img src="_Template/images/photo_04.jpg" alt="" /></a></div>
  48.             </div>
  49.             <div id="flow">
  50.             </div>
  51.         </div>
  52.         <script type="text/javascript" language="javascript">
  53.             $(document).ready(function () {
  54.                 $("#AdTop").blockSlide({
  55.                     speed: "normal",
  56.                     num: 4,
  57.                     timer: 3000,
  58.                     flowSpeed: 300
  59.                 });
  60.             });
  61.         </script>
  62.     </div>
  63.     <!--滚动图片结束 -->
  64. </body>
  65. </html>



  66. 注释:

  67. speed:图片轮播速度

  68. num:图片数量

  69. timer:自动轮播的时间间隔,定时器;

  70. flowSpeed:是滑块移动的速速度



  71. blockSlide插件源码如下:

  72. /**
  73. * @author huajianhuakai */
  74. (function($)
  75. {
  76.     $.fn.blockSlide = function(settings)
  77.     {
  78.         settings = jQuery.extend({
  79.             speed: "normal",
  80.             num: 4,
  81.             timer: 1000,
  82.             flowSpeed: 300
  83.         }, settings);
  84.         return this.each(function()
  85.         {
  86.             $.fn.blockSlide.scllor($(this), settings);
  87.         });
  88.     };
  89.     $.fn.blockSlide.scllor = function($this, settings)
  90.     {
  91.         var index = 0;
  92.         var imgScllor = $("div:eq(0)>div", $this);
  93.         var timerID;
  94.         //自动播放
  95.         var MyTime = setInterval(function()
  96.         {
  97.             ShowjQueryFlash(index);
  98.             index++;
  99.             if (index == settings.num)
  100.                 index = 0;
  101.         }, settings.timer);
  102.         var ShowjQueryFlash = function(i)
  103.         {
  104.             $(imgScllor).eq(i).animate({ opacity: 1 }, settings.speed).css({ "z-index": "100" }).siblings().animate({ opacity: 0 }, settings.speed).css({ "z-index": "0" });
  105.         }
  106.     }
  107. })(jQuery);
复制代码
您需要登录后才可以回帖 登录 | 注册

本版积分规则 发表回复

  

北京盛拓优讯信息技术有限公司. 版权所有 京ICP备16024965号-6 北京市公安局海淀分局网监中心备案编号:11010802020122 niuxiaotong@pcpop.com 17352615567
未成年举报专区
中国互联网协会会员  联系我们:huangweiwei@itpub.net
感谢所有关心和支持过ChinaUnix的朋友们 转载本站内容请注明原作者名及出处

清除 Cookies - ChinaUnix - Archiver - WAP - TOP