实现效果:1、图片每2秒钟切换1次。

2、当鼠标停留在整个页面上时,图片不进行轮播。

3、当点击右下角的小球时,出现该选项的对应图片,而且切换页选项的背景颜色发生相应的变化。

4、当图片发生轮播切换时,在不点击小球前提下,相应的小球背景颜色也自动发生变化。

index.html

<!DOCTYPE html>
<html>
<head>
<title>jQuery实现轮播图</title>
<meta charset="utf-8">
<link rel="stylesheet" type="text/css" href="css/style.css">
<script src="js/jquery-1.12.4.min.js"></script>
<script type="text/javascript" src="js/script.js"></script>
</head>
<body>
<div class="main">
<h3>jQuery实现轮播图</h3>
<!-- 图片轮播 -->
<div class="banner">
<img src="img/1.jpg" />
<img src="img/2.jpg" />
<img src="img/3.jpg" />
<img src="img/4.jpg" />
<img src="img/5.jpg" />
<!-- 上一张、下一张按钮 -->
<a href="javascript:void(0)" class="button prev"></a>
<a href="javascript:void(0)" class="button next"></a>
<!-- 圆点导航 -->
<div class="dots">
<span></span>
<span></span>
<span></span>
<span></span>
<span></span>
</div>
</div>
</div>
</body>
</html>

style.css

*{margin:;padding:;}
body{font-family: " Microsoft YaHei";}
.main{margin:30px auto;width:1200px;text-align: center;}
h3{text-align: center;width:1200px;position: relative;}
/*banner图*/
.banner{width:1200px; height:460px;overflow: hidden;margin-top: 30px;position: relative;border: 10px solid #bbb; }
.banner img{vertical-align: bottom;position: absolute;top:;left:;/*display: none;*/}
/*.banner img.slide-active{display: block;}*/
/*切换按钮*/
.button{position: absolute;width:40px;height:80px;left:;top:50%;margin-top:-40px;}
.prev{background:url(../img/pre2.png) no-repeat center center;}
.next{left: auto;right:;background:url(../img/pre.png) no-repeat center center;}
.button:hover{background-color: #333;opacity: 0.6;filter: alpha(60);}
/*切换小圆点*/
.dots{position: absolute;right:;bottom: 20px;text-align: right;margin-right: 20px;}
.dots span{display: inline-block;width: 12px;height: 12px;border-radius: 50%;line-height:12px;background-color: rgba(7,17,27,0.4);box-shadow:0 0 0 2px rgba(255,255,255,0.9) inset;margin-right: 8px;cursor: pointer;}
.dots span.active{box-shadow: 0 0 0 2px rgba(7,17,27,0.4) inset;background-color: #fff;}

script.js

$(document).ready(function(){
var t,count,
index=0,
len=$(".banner img").length; // 初始化状态,在第一张
$(".banner img:not(:first-child)").hide();
$(".dots span:first-child").addClass("active"); // 滑过鼠标清除定时器,滑开继续
$(".banner").hover(function(){
clearInterval(t);
},
function(){
t=setInterval(showAuto, 2000);
}); //点击小圆点跳转到相应页面并且小圆点样式随之改变
$(".dots span").click(function(){
count=$(this).index();//获取当前点击对象的id属性值
changOption(count);
}); //清除定时器
if(t){
clearInterval(t);
t=null;
} // 每隔两秒自动轮播
t=setInterval(showAuto, 2000); //点击按钮切换
$(".prev").click(function(){
count=$(".active").index();
count--;
if(count < 0){count=len-1;}
changOption(count);
});
$(".next").click(function(){
count=$(".active").index();
count++;
if(count > len-1){count=0;}
changOption(count);
}); // 封装自动切换的showAuto函数
function showAuto(){
index++;
if(index > len-1){index=0;}
changOption(index);
} //封装点击小圆点改变背景及自身样式的changeOption()函数
function changOption(curIndex){
$(".dots span").siblings().removeClass("active");//查找其他子节点并移除类
$(".dots span").eq(curIndex).addClass("active");//给当前点击的对象添加类
$(".banner img").filter(":visible").hide().parent().children().eq(curIndex).show();
index=curIndex;
} });

jquery 轮播图实例的更多相关文章

  1. jQuery轮播图(二)利用构造函数和原型创建对象以实现继承

    本文是在我开始学习JavaScript继承时,对原型继承的一些理解和运用.文中所述的继承方式均是使用js特有的原型链方式,实际上有了ES6的类之后,实现继承的就变得十分简单了,所以这种写法现在也不在推 ...

  2. Jquery 轮播图简易框架

    =====================基本结构===================== <div class="carousel" style="width: ...

  3. jQuery轮播图--不使用插件

    说明:引入jquery.min.js    将轮播图放入imgs文件夹 <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitiona ...

  4. jQuery轮播图(手动点击轮播)

    下面来看看最终做的手动点击轮播效果: 一.原理说明 (1)首先是轮播图的架构,我采用了一个最外边的大div包住两个小div,一个小div里面放四张图片,另一个小div里面放四个数字按钮 (2)对最外边 ...

  5. jQuery轮播图(一)轮播实现并封装

    利用面向对象自己动手写了一个封装好的jquery轮播组件,可满足一般需求,不仅使用简单且复用性高. demo:点此预览 代码地址:https://github.com/zsqosos/componen ...

  6. 《第31天:JQuery - 轮播图》

    源码下载地址:链接:https://pan.baidu.com/s/16K9I... 提取码:0ua2 写这篇文章,当做是对自已这一天的一个总结.写轮播图要准备的东西:三张尺寸大小一样的图片.分为三个 ...

  7. 前端基础功能,原生js实现轮播图实例教程

    轮播图是前端最基本.最常见的功能,不论web端还是移动端,大平台还是小网站,大多在首页都会放一个轮播图效果.本教程讲解怎么实现一个简单的轮播图效果.学习本教程之前,读者需要具备html和css技能,同 ...

  8. jquery 轮播图

    slider.js (function(){ /** parent //父容器 changeTime //每次间隔几秒切换下一条 leaveTime //鼠标从小图上离开过后几秒继续切换 index ...

  9. 超级简单的jquery轮播图demo

    <!DOCTYPE html> <html> <head> <meta charset="UTF-8"> <title> ...

随机推荐

  1. 关闭MongoDB

    以下方法干净地关闭MongoDB: 完成所有挂起的操作.刷新数据到数据文件.关闭所有的数据文件 1. > use admin switched to db admin > db.shutd ...

  2. STL容器分析--map

    映射和多重映射基于某一类型Key的键集的存在,提供对T类型的数据进行快速和高效的检索.

  3. Calendar类经常用法 日期间的转换 set方法有巨坑

           今天发现项目的工具类方法有个bug,并且还能迷惑你的bug,刚開始也是非常迷惑,由于这个bug之前出现过,可是过了两天就自己好了.今天又出现了.哦对,今天是 2017年3月31日,之 ...

  4. jQuery国际化插件 jQuery.i18n.properties 【轻量级】

    jQuery.i18n.properties是一款轻量级的jQuery国际化插件,能实现Web前端的国际化. 国际化英文单词为:Internationalization,又称i18n,“i”为单词的第 ...

  5. JS prototype 属性

    String.prototype.trim=function(){ return this.replace(/(^\s*)|(\s*$)/g, "");}

  6. Failure [INSTALL_FAILED_OLDER_SDK] [每件问题100块]

    问题描述:链接真机时候出现的问题 解决问题: minSdkVersion 10targetSdkVersion 22 修改这两个值

  7. ubuntu:好用的help命令

    以前光知道如何不清楚某个命令的用法可以打上后缀 ‘ --help' 现在刚发现,原来还有help命令来帮忙,如果你安装的是中文支持,在ubuntu上, 那么部分命令说明还是中文版哦. 举例: help ...

  8. C++语言基础(23)-拷贝构造函数

    当以拷贝的方式初始化一个对象时,会调用一个特殊的构造函数,就是拷贝构造函数(Copy Constructor). 例如: #include <iostream> #include < ...

  9. LDAP实战应用指南

    第1章 ladp master服务安装 1.1 安装前系统环境准备 1.1.1 查看系统版本信息 [root@ldap-server ~]# cat /etc/redhat-release CentO ...

  10. [Delphi] 常用字符集简介

    转载 http://www.cnblogs.com/yangyxd/articles/4778483.html 字符集 ANSI (ASCII)美国信息互换标准编码 GB 2312信息交换用汉字编码字 ...