html部分:

<!DOCTYPE html>
<html>

<head>
<meta charset="UTF-8">
<title>图片轮播</title>
<link rel="stylesheet" href="css/style.css" />
</head>

<body>
<h3>jQuery实现轮播图</h3>
<div class="main">
<div class="box" id="box">
<!-- 图片区域 bagin -->
<a href="#">
<div class="img img1"></div>
</a>
<a href="#">
<div class="img img2"></div>
</a>
<a href="#">
<div class="img img3"></div>
</a>
<a href="#">
<div class="img img4"></div>
</a>
<a href="#">
<div class="img img5"></div>
</a>
<!-- end -->

<!--上一张-->
<span class="pre" id="prev">
                  <a href="#"><img src="img/pre2.png"/></a>
                </span>
<!--下一张-->
<span class="pre" id="next" style="right: 0;">
                  <a href="#"><img src="img/pre.png"/></a>
                </span>
<!--小圆点-->
<ul>
<li class="active"></li>
<li></li>
<li></li>
<li></li>
<li></li>
</ul>
</div>
</div>
<script type="text/javascript" src="js/jquery-1.11.0.js"></script>
<script type="text/javascript" src="js/base.js"></script>
</body>

</html>

css部分:

/*样式重置*/

* {
margin: 0;
padding: 0;
}

body {
font-family: Microsoft YaHei;
}

li {
list-style: none;
}

/*main bagin*/
h3{
text-align: center;
margin-top: 20px;
}
.main {
width: 1224px;
height: 480px;
margin: 20px auto;

}

/*end*/

/*box bagin*/

.box {
width: 1200px;
height: 460px;
overflow: hidden;
position: relative;
padding-top: 10px;
padding-left: 12px;
}

/*end*/

/*图片共同样式 bagin*/

.img {
width: 1200px;
height: 460px;
background: no-repeat;
}

/*end*/

.img1 {
background-image: url(../img/1.jpg);
}

.img2 {
background-image: url(../img/2.jpg);
}

.img3 {
background-image: url(../img/3.jpg);
}

.img4 {
background-image: url(../img/4.jpg);
}

.img5 {
background-image: url(../img/5.jpg);
}

/*箭头共同样式 bagin*/
.pre{
display: inline-block;
width:40px;
height:60px;
position: absolute;
top: 50%;
text-align: center;
line-height: 76px;
}
/*end*/

/*移入箭头的样式*/
span.active{
background: rgba(0,0,0,0.5);
}

ul {
position: absolute;
top:93%;
right: 20px;
}
li{
display: inline-block;
width: 10px;
height: 10px;
border: 1px solid #fff;
border-radius: 10px;
margin-left: 8px;

cursor: pointer;
}
/*点击小圆点时的样式*/
li.active{

}

js部分:

$(function() {
var timer = null,
index = 0,
len=$("#box div").length;
//console.log(len)

//移出函数,图片自动轮播
    $("#box").mouseout(function(){
        clearInterval(timer)
        autoimg()
    })
    //移入函数,图片停止轮播
    $("#box").mouseover(function(){
        clearInterval(timer)
    })
    //页面打开自执行
    $("#box").mouseout()
    //下一张点击事件
    $("#next").click(function(){
        index++
         if (index>len-1) {
         index=0
         }
         tab()
    })
    //上一张点击事件
    $("#prev").click(function(){
     index--
         if (index<0) {
         index=len-1
         }
         tab()
    })
    //上下张移入移出事件 bagin
    $("#next").mouseover(function(){
       $(this).addClass("active")
    })
    $("#next").mouseout(function(){
     $(this).removeClass("active")
    })
    $("#prev").mouseover(function(){
       $(this).addClass("active")
    })
    $("#prev").mouseout(function(){
     $(this).removeClass("active")
    })
    //end
    
    //小圆点点击事件
    $("ul li").click(function(){
      index=$(this).index()
      tab()
    })
    
    function tab(){
       $("#box div").hide().eq(index).show()
       $("ul li").removeClass().eq(index).addClass("active")
    }
    //时间函数
    function autoimg(){
     timer=setInterval(function(){
       index++
         if (index>len-1) {
         index=0
         }
         tab()
     },2000)
    }
    
   
})

jQuery-实现图片轮播的更多相关文章

  1. jQuery个性化图片轮播效果

    jQuery个性化图片轮播效果 购物产品展示:图片轮播器<效果如下所示> 思路说明: 每隔一段时间,实现图片的自动切换及选项卡选中效果,鼠标划入图片动画停止,划出或离开动画开始 两个区域: ...

  2. PgwSlideshow-基于Jquery的图片轮播插件

    0 PgwSlideshow简介 PgwSlideshow是一款基于Jquery的图片轮播插件,基本布局分为上下结构,上方为大图轮播区域,用户可自定义图片轮播切换的间隔时间,也可以通过单击左右方向按键 ...

  3. jQuery.YesShow - 图片轮播插件(带图片放大功能)

    jQuery.YesShow - 图片轮播插件(带图片放大功能) 使用简单,原文件只要这样就可以了:<div id="yes">         <ul> ...

  4. (转)jquery实现图片轮播

    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/ ...

  5. 基于jquery的图片轮播 (IE8以上)

    <!doctype html> <html> <head> <meta charset="utf-8"> <title> ...

  6. jQuery实现图片轮播

    之前有碰到过jQuery实现列表自动滚动,这次的图片轮播在原理上与之相同,只有一些细微的差别,就是需要在图片的右下角显示当前图片的序号,效果如下: 先看一看html代码,以及对应的css代码: < ...

  7. Javascript和jQuery WordPress 图片轮播插件, 内容滚动插件,前后切换幻灯片形式显示

    用于在有限的网页空间内展示一组产品图片或者照片,同时还有非常吸引人的动画效果.本文向大家推荐12款实用的 jQuery 图片轮播效果插件,帮助你在你的项目中加入一些效果精美的图片轮播效果,希望这些插件 ...

  8. 原生js和jquery实现图片轮播特效

    本文给大家分享的是使用原生JS和JQ两种方法分别实现相同的图片轮播特效,十分的实用,也非常方便大家对比学习原生js和jQuery,有需要的小伙伴可以参考下. 1)首先是页面的结构部分对于我这种左右切换 ...

  9. 原生js和jquery实现图片轮播特效(转)

    本文给大家分享的是使用原生JS和JQ两种方法分别实现相同的图片轮播特效,十分的实用,也非常方便大家对比学习原生js和jQuery,有需要的小伙伴可以参考下. 1)首先是页面的结构部分对于我这种左右切换 ...

  10. html css+div+jquery实现图片轮播

    一直想自己动手做一个图片轮播的控件,查查网上的资料大多引用已经做好的组件,其原理算法不是很清楚,于是自己用jquery写了一个.先看下效果图: 主要界面实现思路如下: 1.新建一个div宽度为100% ...

随机推荐

  1. Spring:AOP

    摘要 本文内容为我在网上搜集Spring AOP资料的汇总.摘抄. AOP是一种编程思想,其对不同对象进行了横向的抽象,将不同对象的.和主流程无关的公共逻辑抽象出来以方便维护.AOP的实现基础为AOP ...

  2. 2019南昌网络赛-I(单调栈+线段树)

    题目链接:https://nanti.jisuanke.com/t/38228 题意:定义一段区间的值为该区间的和×该区间的最小值,求给定数组的最大的区间值. 思路:比赛时还不会线段树,和队友在这题上 ...

  3. mysql5.7.21安装要点记录

    下载的是Zip解压缩版,Windows系统,因为很久没有在Windows上安装过,这次安装发现了几处和以前安装不一样的地方,特记录如下,供大家参考 MySQL配置文件位置 bin目录下的mysql_c ...

  4. tomcat启动慢

     securerandom.source=file:/dev/./urandom  搜索  /""

  5. paloalto防火墙的优势

    1.所有 Palo Alto Networks 防火墙提供一个可用于执行防火墙管理功能的带外管理端口 (MGT).通过使用该 MGT 端口,可以将防火墙的管理功能与数据处理功能分开,从而保护对防火墙的 ...

  6. 分支&循环

    分支 单分支 if 条件: 满足条件后要执行的代码 双分支 if 条件: 满足条件执行代码 else: if条件不满足就走这段 多分支: if 条件: 满足条件执行代码 elif 条件: 上面的条件不 ...

  7. java 调用存储过程

    1.java 中调用pl/sql 中的存储过程 call 存储过程的名称(参数名称,参数名称)  在service 层中调用  存储过程  String  sql=" call  proc_ ...

  8. CentOS7下安装Redis

    一.下载redis wget http://download.redis.io/releases/redis-4.0.6.tar.gz 二.解压 tar -zxvf redis-4.0.6.tar.g ...

  9. API Test WebApiTestClient工具安装及使用

    一.guget安装: 1.解决方案右键-管理解决方案的nuget程序包打开如下图: 搜索WebApiTestClient,然后选择查询出的项目,右边点击安装即可:   2.安装会有如下图提示: 确定即 ...

  10. 颜色16进制转为RGB格式

    <script> 2 function getRGB(str){ var arr = str.split(""); var myred = arr[1]+arr[2]; ...