首页 技术 正文
技术 2022年11月20日
0 收藏 657 点赞 2,586 浏览 1826 个字

// 轮播图

主要实现思想:

  a.第一层div,设置overflow为hidden。

  b.里面是一个ul,每个li里面有个img或者为每个li设置背景图片也可以。

  c.li设置为左浮动,排成一行,还有ul的宽度设置成li宽度的总和,不然li会换行!

  d.点击向右按钮:

    (1)让整个ul向左滑动,margin-left的滑动距离为为负的li宽度;

    (2)把第一个li放到ul里的最后位置;

    (3)设置ul的margin-left为0px;

    Tips:以上步骤必须放到ul向左滑动动画的回调函数里面。

  e.点击向左按钮:

    (1)先把ul的margin-left的距离设置为负的li宽度;

    (2)把最后一个li放到ul里的第一个位置;

    (3)设置ul的margin-left为0px(此步骤需写在animate动画函数中)。

具体例子:

  CSS代码:  

  

  * {
    margin:;
    padding:;
  }
  ul {
    list-style: none;
  }  .list {
    width: 1000px;
    padding: 10px;
    overflow: hidden;
    margin: 100px auto;
    border: 1px solid;
  }
  .list-cont {
    display: inline-block;
    width: 1350px;
  }
  .list-cont li {
    width: 200px;
    height: 180px;
    float: left;
    border: 1px solid;
    text-align: center;
    line-height: 180px;
    font-size: 24px;
    margin-right: 5px;
  }
  .btn {
    display: table;
    margin: 10px auto;
    border: 1px solid;
    padding: 5px 10px;
    cursor: pointer;
  }
  .btn:hover {
    background-color: #ccc;
  }

  HTML代码:

  

  <div class="list">
    <ul class="list-cont">
      <li>1</li>
      <li>2</li>
      <li>3</li>
      <li>4</li>
      <li>5</li>
      <li>6</li>
    </ul>
    <button class="btn scroll-left">向左滚动</button>
    <button class="btn scroll-right">向右滚动</button>
  </div>

  JS代码:

  因为此轮播图是基于JQ的animate,所有必须要引用JQ文件才行!

  

  $(function(){
    // ul的宽度
    $(".list-cont").width($(".partner-list li").length * 200);    // 点击右箭头        $(".scroll-right").click(function(){
      $(".list-cont").stop().animate({"margin-left":"-200px"},600,function(){
        $(".list-cont>li").first().appendTo($(".list-cont"));
        $(".list-cont").css("margin-left","0");
      });
    });    // 点击左箭头        $(".scroll-left").click(function(){
      $(".list-cont").css("margin-left","-200px");
      $(".list-cont>li").last().prependTo($(".list-cont"));
      $(".list-cont").stop().animate({"margin-left":"0"});
    });  });
相关推荐
python开发_常用的python模块及安装方法
adodb:我们领导推荐的数据库连接组件bsddb3:BerkeleyDB的连接组件Cheetah-1.0:我比较喜欢这个版本的cheeta…
日期:2022-11-24 点赞:878 阅读:9,082
Educational Codeforces Round 11 C. Hard Process 二分
C. Hard Process题目连接:http://www.codeforces.com/contest/660/problem/CDes…
日期:2022-11-24 点赞:807 阅读:5,557
下载Ubuntn 17.04 内核源代码
zengkefu@server1:/usr/src$ uname -aLinux server1 4.10.0-19-generic #21…
日期:2022-11-24 点赞:569 阅读:6,406
可用Active Desktop Calendar V7.86 注册码序列号
可用Active Desktop Calendar V7.86 注册码序列号Name: www.greendown.cn Code: &nb…
日期:2022-11-24 点赞:733 阅读:6,179
Android调用系统相机、自定义相机、处理大图片
Android调用系统相机和自定义相机实例本博文主要是介绍了android上使用相机进行拍照并显示的两种方式,并且由于涉及到要把拍到的照片显…
日期:2022-11-24 点赞:512 阅读:7,815
Struts的使用
一、Struts2的获取  Struts的官方网站为:http://struts.apache.org/  下载完Struts2的jar包,…
日期:2022-11-24 点赞:671 阅读:4,898