jquery 简单幻灯片

<html>
 <head>
  <title>jquery sliders</title>
  <style>
    #bigger{width:120px;height:80px;overflow:hidden;margin:0px;padding:0px;}
    #big {width:840px;margin:0px;padding:0px;position:relative;}
    #big div {width:120px;text-align:center;margin:0px;padding:0px;float:left;}
  </style>
  <script src="jquery.js"></script>
  <script>
   var justClick = 0;
   var timer = new Date().getTime();
   window.onload = function() {
    var arr = [];
    $("#big div").each(function() {
     arr.push($(this).position());
    }).each(function(i) {
     $(this).css({
      position : 'absolute',
      top : arr[i].top ,
      left : arr[i].left
     });
    });
    $("#control button").mouseover(function() {
     changePicture($(this));
    });
    setInterval(function() {
     if( (new Date().getTime() - timer) > 2000 ) {
      var index = justClick + 1;
      if(index == 7) {
       index = 0;
      }
      changePicture($("#control button:eq(" + index + ")"));
      timer = new Date().getTime();
     }
    } , 3000);
   };
   function changePicture(node) {
     var index = node.html() - 1;
     var len = $("#big div").length;
     if(index != justClick) {
      for(var i = 0 ; i < len ; i++) {
        $("#big div:eq(" + i + ")").stop(true  , true).animate({left : "-=" + (index - justClick) * 120  + "px"} , 300);
      }
      justClick = index;
      timer = new Date().getTime();
     }
   }
  </script>
</head>
 <body>
  <div id="bigger">
   <div id="big">
    <div><img src="images/1_s.jpg"></div>
    <div><img src="images/2_s.jpg"></div>
    <div><img src="images/3_s.jpg"></div>
    <div><img src="images/4_s.jpg"></div>
    <div><img src="images/5_s.jpg"></div>
    <div><img src="images/6_s.jpg"></div>
    <div><img src="images/7_s.jpg"></div>
   </div>
  </div>
  
  <div id="control">
   <button>1</button>
   <button>2</button>
   <button>3</button>
   <button>4</button>
   <button>5</button>
   <button>6</button>
   <button>7</button>
  </div>
  
 </body>
</html>

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值