栏目分类:
子分类:
返回
名师互学网用户登录
快速导航关闭
当前搜索
当前分类
子分类
实用工具
热门搜索
名师互学网 > IT > 软件开发 > Web开发 > JavaScript

jQuery实现一个简单的轮播图

JavaScript 更新时间: 发布时间: IT归档 最新发布 模块sitemap 名妆网 法律咨询 聚返吧 英语巴士网 伯小乐 网商动力

jQuery实现一个简单的轮播图

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

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

转载请注明:文章转载自 www.mshxw.com
本文地址:https://www.mshxw.com/it/89940.html
我们一直用心在做
关于我们 文章归档 网站地图 联系我们

版权所有 (c)2021-2022 MSHXW.COM

ICP备案号:晋ICP备2021003244-6号