最简单的图片轮播实现

以下代码保存为一个xx.html即可运行。

<html
    <head>
        <style>
        #banner {                                                                                                                                                                                                                                                                                                                                                                               
   border:0 none;                                                                                                              
   float:left;                                                                                                                 
   height:225px;                                                                                                               
   margin:2px 16px 0 12px;                                                                                                     
   width:270px;                                                                                                                
   border:1px solid #CCCCCC;                                                                                                                                                                                                                                 
   }       
 #banner img {                                                                                                               
       border:0px;                                                                                                             
       width:270px;                                                                                                            
       height:225px;                                                                                                           
   }     
 #play_text {                                                                                                                
       position:absolute;                                                                                                      
       margin:190px 0 0 0;                                                                                                     
       height:24px;                                                                                                            
       width:290px;                                                                                                            
       z-index:1002;                                                                                                           
   }                                                                                                                           
   #play_text ul {                                                                                                             
       list-style-type:none;                                                                                                   
       padding-right:24px;                                                                                                     
       float:right;                                                                                                            
       height:20px;                                                                                                            
       display:block;                                                                                                                               
}
#play_text ul li {
    width:18px;
    height:18px;
    line-height:18px;
    float:left;
    background:#000;
    border:2px solid #fff;
    display:block;
    color:#fff;
    text-align:center;
    margin:1px;
    font-weight:700;
    cursor:pointer;

    background:#FFFFFF none repeat scroll 0 0;
    border:1px solid #74A8ED;
    color:#74A8ED;

}
   #play_text ul li.selected{                                                                                                  
       background:#f00;                                                                                                        
   background:#74A8ED none repeat scroll 0 0;                                                                                  
   border:1px solid #EEEEEE;                                                                                                   
   color:#FFFFFF;                                                                                                              
   font-size:16px;                                                                                                             
   font-weight:700;                                                                                                            
   }                                                                                                                           
   #play_list a {                                                                                                              
       display:block;                                                                                                          
       position:absolute;                                                                                                      
       overflow:hidden                                                                                                         
   }             
        </style>
        <script src="http://ajax.googleapis.com/ajax/libs/jquery/1.3.1/jquery.min.js" type="text/javascript"></script>
        <script language="javascript">
        $(function (){
      picAuto(4000);
      var t = setInterval('AutoScroll("#scrollDiv")',1500);
 
      $('#scrollDiv').hover(
        function () {
          clearInterval(t);
        },
        function () {
          t = setInterval('AutoScroll("#scrollDiv")',1500);
        }
      );
  });
 
  //首页轮播图片
  function picAuto(_AutoTime) {
      var t = n = 0; count = $("#play_list a").size();
      $("#play_list a:not(:first-child)").hide();
      $("#play_text li:first-child").addClass("selected");
      $("#play_text li").click(function() {
          var i = $(this).text() - 1;
          n = i;
          if (i >= count) return;
          $("#play_list a").filter(":visible").fadeOut(500).parent().children().eq(i).fadeIn(1000);
          $(this).addClass("selected").siblings().removeClass("selected");
      });
      t = setInterval("showAuto()", _AutoTime);
      $("#pic").hover(function(){clearInterval(t)}, function(){t = setInterval("showAuto()", _AutoTime);});
      //移动到图片上后不自动跳转图片
  }
  function showAuto() {
      n = n >= (count - 1) ? 0 : ++n;
      $("#play_text li").eq(n).trigger('click');
  }
  function AutoScroll(obj){
      var myheight = $('.new_prod_box').height();
      $(obj).find("ul:first").animate({
          marginTop:'-'+myheight
          },500,function(){
          $(this).css({marginTop:"0px"}).find("li:first").appendTo(this);
          }
      );
  }
            </script>
    </head>
    <body>
         <div id="banner">   
             <div id="play_text">
                 <ul>
                     <li>1</li>
                     <li>2</li>
                     </ul>  
                     </div>
                     <div id="play_list">
                         <a href="http://www.qihoo.com">
<img src="http://img.qihoo.com/images/2008/qihoo/logo2010.jpg"/>
</a>
<a href="http://www.yiiframework.com">
<img src="http://www.yiiframework.com/images/logo.gif"/>
</a>
                         </div>
                          </div>
                         
    </body>
</html>

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值