jQuery实现一个简单的轮播图

2019-11-22,,,

html代码:

<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<title>轮播图练习</title>
<link rel="stylesheet" href="css/css.css" rel="external nofollow" type="text/css"/>
</head>
<body>
<ul class="back">      <!-- 背景图片 -->
  <li class="l1"></li>
  <li class="l2"></li>
  <li class="l3"></li>
  <li class="l4"></li>
  <li class="l5"></li>
</ul>
<ul class="point">     <!-- 控制按钮 -->
  <li class="active"></li>
  <li></li>
  <li></li>
  <li></li>
  <li></li>
</ul>
<div class="btn">     <!-- 左右控制按钮 -->
  <span class="prev"></span>
  <span class="next"></span>
</div>
</body>
<script src="js/jquery-1.7.2.js"></script>
<script src="js/jq.js"></script>
</html>

css代码:

*{margin:0; padding: 0;}
ul li{list-style: none;}
.back{height: 400px; overflow: hidden; margin-top:100px;}
.back li{width: 100%; height: 400px; margin:0 auto;}
.back li.l1{background: red;}
.back li.l2{background: yellow;}
.back li.l3{background: blue;}
.back li.l4{background: black;}
.back li.l5{background: green;}
.point{text-align: center; margin-top: -30px;}
.point li{ width: 20px; height: 20px; border:2px solid #fff; border-radius: 10px; box-sizing:border-box; display: inline-block;}
.point li.active{background: #fff;}
.btn{ position: relative;}
.btn span{ display: inline-block; vertical-align: top; width: 100px; height: 100px; background: rgba(0,0,0,.5); position: absolute; top:-235px; cursor: pointer;}
.btn .prev{left: 0}
.btn .next{ right: 0;}

js代码:

$(function(){
  function banner(a,b,c,d,e){         // a是背景图,b是active,c是背景对应按钮,d是上一页,e是下一页
    index=0;
    len=$(a).length-1;
    function teb(index){
      $(c).eq(index).addClass(b).siblings('').removeClass(b);
      $(a).eq(index).fadeIn(300).addClass('curr').siblings('').fadeOut(300).removeClass('curr');
    };
    $(c).click(function(){
      index=$(this).index();
      teb(index);
    });
    $(d).click(function(){
      index--;
      if(index<0){
        index=len;
      };
      teb(index);
    });
    $(e).click(function(){
      index++;
      if(index>len){
        index=0;
      };
      teb(index);
    });
    function timeRun(){
      time=setInterval(function(){
        index++;
        if(index>len){
          index=0;
        };
        teb(index);
      },3000);
    };
    timeRun();
  };
  banner('.back>li','active','.point>li','.prev','.next');
});

以上就是本文的全部内容,希望本文的内容对大家的学习或者工作能带来一定的帮助,同时也希望多多支持北冥有鱼!

您可能感兴趣的文章:

  • jquery实现左右轮播图效果
  • JQuery和html+css实现带小圆点和左右按钮的轮播图实例
  • jquery版轮播图效果和extend扩展
  • jQuery制作全屏宽度固定高度轮播图(实例讲解)
  • jquery实现左右滑动式轮播图
  • jQuery按需加载轮播图(web前端性能优化)
  • jquery实现轮播图效果
  • 用jQuery实现优酷首页轮播图
  • jQuery无缝轮播图代码
  • jquery 实现轮播图详解及实例代码
  • 原生Javascript和jQuery做轮播图简单例子
  • jQuery实现简洁的轮播图效果实例
  • jquery写出PC端轮播图实例

《jQuery实现一个简单的轮播图.doc》

下载本文的Word格式文档,以方便收藏与打印。