用 JS 点击左右按钮 使图片切换 - 最精简版

  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. <title>实用的图片切换</title>

  6. <script type="text/javascript" src="https://ajax.googleapis.com/ajax/libs/jquery/1.4.1/jquery.js"></script>

  7. <!--<script type="text/javascript" src="jquery_change.js"></script>-->

  8. <style type="text/css">

  9.  body,ul,li { padding:0; margin:0}

  10.  ul,li { list-style:none}

  11.  .img-scroll { position:relative; margin:20px auto; width:440px;}

  12.  .img-scroll .prev,.img-scroll .next { position:absolute; display:block; width:50px; height:100px; background-color:#000;

  13.  top:0; color:#FFF; text-align:center; line-height:100px}

  14.  .img-scroll .prev { left:0;cursor:pointer;}

  15.  .img-scroll .next { right:0;cursor:pointer;}

  16.  .img-list { position:relative; width:320px; height:100px; margin-left:60px; overflow:hidden}

  17.  .img-list ul { width:9999px;}

  18.  .img-list li { float:left; display:inline; width:100px; margin-right:10px; height:100px; background-color:#BDBDDF; text-align:center; line-height:100px;}

  19. </style>

  20. </head>

  21. <body>

  22. <div class="img-scroll">

  23.     <span class="prev">prev</span>

  24.     <span class="next">next</span>

  25.     <div class="img-list">

  26.         <ul>

  27.             <li><img style="width:100px;height:100px;" src="./img/cat.jpg"></li>

  28.             <li><img style="width:100px;height:100px;" src="./img/katong.jpg"></li>

  29.             <li><img style="width:100px;height:100px;" src="./img/meinv.jpg"></li>

  30.             <li><img style="width:100px;height:100px;" src="./img/mm.jpg"></li>

  31.             <li><img style="width:100px;height:100px;" src="./img/慢慢.jpg"></li>

  32.             <li><img style="width:100px;height:100px;" src="./img/美食杰-糖糖.jpg"></li>

  33.             <li><img style="width:100px;height:100px;" src="./img/未命名44.jpg"></li>

  34.         </ul>

  35.     </div>

  36. </div>

  37. <script type="text/javascript">

  38.  function DY_scroll(wraper,prev,next,img,speed,or)

  39.  {

  40.   var wraper = $(wraper);

  41.   var prev = $(prev);

  42.   var next = $(next);

  43.   var img = $(img).find('ul');

  44.   var w = img.find('li').outerWidth(true);

  45.   var s = speed;

  46.   next.click(function()

  47.        {

  48.         img.animate({'margin-left':-w},function()

  49.                   {

  50.                    img.find('li').eq(0).appendTo(img);

  51.                    img.css({'margin-left':0});

  52.                    });

  53.         });

  54.   prev.click(function()

  55.        {

  56.         img.find('li:last').prependTo(img);

  57.         img.css({'margin-left':-w});

  58.         img.animate({'margin-left':0});

  59.         });

  60.   if (or == true)

  61.   {

  62.    ad = setInterval(function() { next.click();},s*1000);

  63.    wraper.hover(function(){clearInterval(ad);},function(){ad = setInterval(function() { next.click();},s*1000);});


  64.   }

  65.  }

  66.  DY_scroll('.img-scroll','.prev','.next','.img-list',3,false);// true为自动播放,不加此参数或false就默认不自动

  67. </script>

  68. </body>

  69. </html>


转载于:https://my.oschina.net/u/920045/blog/405610

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值