zoukankan      html  css  js  c++  java
  • jquery手写焦点轮播图-------解决最后一张无缝跳转第一张的问题

    <!DOCTYPE html>
    <html lang="en">
    <head>
        <meta charset="UTF-8">
        <title>轮播图</title>
        <style>
            *{padding: 0;margin: 0;list-style-type: none;}
            .wrap{width: 520px;height: 280px;margin: 50px auto;}
            .banner{width: 520px;height: 280px;overflow: hidden;position: relative;}
            .imgList{width: 1560px;height: 280px;overflow: hidden;position: absolute;left: 0;}
            .imgList li{float: left;width: 520px;height: 280px;}
            #left,#right{position: absolute;top: 120px;z-index: 50;cursor: pointer;}
            #left{left: 0px;}
            #right{right: 0px;}
        </style>
    </head>
    <body>
        <div class="wrap">
            <div class="banner">
                <ul class="imgList">
                    <li><img src="img/ban01.png"></li>
                    <li><img src="img/ban02.png"></li>
                    <li><img src="img/ban03.png"></li>
                </ul>
                <img src="img/left.png" id="left">
                <img src="img/right.png" id="right">
            </div>
        </div>
    
      <script type="text/javascript" src="jquery.min.js"></script>
      <script type="text/javascript">
    
    /*.....这样写无法实现最后一张无缝跳转第一张......*/
    /*      var curIndex = 0;
          var imgLen = $(".imgList li").length;
          var autoChange = setInterval(function(){
              if(curIndex<imgLen-1)
                  {
                      curIndex++;}
              else{
                  curIndex = 0;}
              changeTo(curIndex);
          },2500);
          function changeTo(index){
              var goLeft = index * 520;
              $(".imgList").animate({left:"-" + goLeft + "px"},500);
          }*/
    
    /*.....这样写可以实现最后一张无缝跳转第一张(原理就是把第一张克隆到最后一张后面)......*/
        var timer = setInterval(function() {
                    $(".imgList").animate({
                        "left": "-520px"
                    }, 500, function(){
                        $(".imgList").children("li:first").insertAfter($(".imgList").children("li:last"));
                        $(".imgList").css("left", 0);
                    });
                }, 2500);
    
    下面这种写法等同上面,只是insertAfter那里写法不一样。
    /* var timer = setInterval(function() { $(".imgList").animate({ "left": "-520px" }, 500, function(){ $(".imgList li:first").insertAfter($(".imgList li:last")); $(".imgList").css("left", 0); }); }, 2500);*/ </script> </body> </html>
  • 相关阅读:
    Orchard1.4发布
    13个MVC的扩展
    不完全接触Node.js
    mac软件
    在Apworks框架中解除NHibernateContext与NHibernateRepository的依赖关系
    mac下我常用的一些软件
    在.NET应用程序中访问Excel的几种方式
    Visual Studio 11 Beta 官方下载地址
    欢迎使用 Windows 8 – Consumer Preview
    PHP学习系列之 环境配置
  • 原文地址:https://www.cnblogs.com/liuyanxia/p/5794837.html
Copyright © 2011-2022 走看看