jQuery实现一个简单的轮播图

发布时间:2020-08-25 02:23:35 作者:nameless-212
来源:脚本之家 阅读:174

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');
});

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

推荐阅读:
  1. jQuery实现简单的轮播图
  2. 使用jQuery怎么实现一个轮播图功能

免责声明:本站发布的内容(图片、视频和文字)以原创、转载和分享为主,文章观点不代表本网站立场,如果涉及侵权请联系站长邮箱:is@yisu.com进行举报,并提供相关证据,一经查实,将立刻删除涉嫌侵权内容。

jquery 轮播 ue

上一篇:Python3目录操作

下一篇:Android仿QQ长按弹出删除复制框

相关阅读

您好,登录后才能下订单哦!

密码登录
登录注册
其他方式登录
点击 登录注册 即表示同意《亿速云用户服务条款》