再平常的浏览器页面,轮播图都是必不可缺少的一个板块,在这总结了一下轮播图基本的一些样式

首先介绍一下,本文实现的轮播图的基本效果:  

  1. 3s自动切换图片,图片切换时提示点跟随切换
  2. 鼠标划到图片上,自动切换轮播图停止
  3. 指示点划过切换对应的图片,图片切换时提示点跟随切换
  4. 点击上一页下一页按钮切换图片
  5. 图片切换时有渐变的效果

下表面开始代码的书写

css代码

/*初始化浏览器默认样式*/
*{
margin:;
padding:;
}
/*sowingMap*/
.sowingMap{
width: 800px;
height: 500px;
margin: 0 auto;
position: relative;
overflow: hidden;
}
/*imgPart*/
.imgPart{
width: 800px;
height: 500px;
position: absolute;
}
/*imgSwitch*/
.imgSwitch{
width: 800px;
height: 500px;
position: absolute;
list-style: none;
display: none;
cursor: pointer;
}
.imgSwitch img{
width: 100%;
height: 500px;
}
.imgShow{
display: block;
}
/*spotPart*/
.spotPart{
position: absolute;
bottom:;
height: 40px;
left: 36%;
}
.spotPart p{
width: 20px;
height: 20px;
border-radius: 100%;
background-color: #fff;
float: left;
margin-left: 20px;
cursor: pointer;
}
/*提示点的选中颜色*/
.spotPart .spotColor{
background-color: #f00;
}
/*上一张下一张切换部分*/
.preImg , .nextImg{
width: 70px;
height: 70px;
border-radius: 100%;
background-color: rgba(255,255,255,0.5);
text-align: center;
line-height: 70px;
font-size: 30px;
color: #f5f5f5;
position: absolute;
top: 190px;
cursor: pointer;
display: none;
}
.preImg{
left: -35px;
text-indent: 25px;
}
.nextImg{
right: -35px;
text-indent: -25px;
}

css代码块

html代码

<div class="sowingMap">
<ul class="imgPart">
<li class="imgSwitch imgShow"><img src="img/1.jpg"/></li>
<li class="imgSwitch"><img src="img/2.jpg"/></li>
<li class="imgSwitch"><img src="img/3.jpg"/></li>
<li class="imgSwitch"><img src="img/4.jpg"/></li>
<li class="imgSwitch"><img src="img/5.jpg"/></li>
</ul>
<div class="spotPart">
<p class="spotColor"></p>
<p></p>
<p></p>
<p></p>
<p></p>
</div>
<div class="loopChange">
<p class="preImg">&lt;</p>
<p class="nextImg">&gt;</p>
</div>
</div>

轮播图功能实现的js代码

//获取元素的个数
var count = $('.imgSwitch').length;
var num = 0;
var start = null;
//业务1:实现3s钟自动循环切换图片,图片切换时提示点跟随切换,图片切换时有渐变的效果
function loopStart() {
clearInterval(start);
start = setInterval(function() {
//首先清楚所有样式
$('.imgSwitch').hide();
//取余方式对num取值进行判断
num = (num + 1) % count;
//图片渐入
$('.imgSwitch').eq(num).fadeIn(1000);
$('.spotPart p').eq(num).addClass("spotColor").siblings().removeClass("spotColor");
}, 2000);
}
loopStart(); //业务2:鼠标划到图片上,轮播图停止自动切换,划出后继续播放
$('.imgSwitch').mouseover(function() { //鼠标划过停止
clearInterval(start);
});
$('.imgSwitch').mouseout(function() { //鼠标划出
loopStart();
}); //业务三:指示点划过切换对应的图片,图片切换时提示点跟随切换
$('.spotPart p').mouseover(function() {
clearInterval(start);
//首先清楚所有样式
$('.imgSwitch').hide();
$('.imgSwitch').eq($(this).index()).fadeIn(1000);
$('.spotPart p').eq($(this).index()).addClass("spotColor").siblings().removeClass("spotColor");
});
$('.spotPart p').mouseout(function() {
loopStart();
});
//业务四:点击上一页下一页切换
$('.sowingMap').mouseover(function() {
clearInterval(start);
$('.loopChange p').show();
});
$('.sowingMap').mouseout(function() {
loopStart();
$('.loopChange p').hide();
});
$('.preImg').click(function() {
$('.imgSwitch').hide();
if(num <= 0) {
num = 4;
$('.imgSwitch').eq(num).fadeIn(1000);
$('.spotPart p').eq(num).addClass("spotColor").siblings().removeClass("spotColor");
}
else if(num <= 4) {
$('.imgSwitch').eq(num-1).fadeIn(1000);
$('.spotPart p').eq(num-1).addClass("spotColor").siblings().removeClass("spotColor");
num--;
}
});
$('.nextImg').click(function() {
$('.imgSwitch').hide();
if(num >= 4) {
num = 0;
$('.imgSwitch').eq(num).fadeIn(1000);
$('.spotPart p').eq(num).addClass("spotColor").siblings().removeClass("spotColor");
}
else if(num >= 0) {
$('.imgSwitch').eq(num+1).fadeIn(1000);
$('.spotPart p').eq(num+1).addClass("spotColor").siblings().removeClass("spotColor");
num++;
}
});

注意,不要忘记引入jquery的语法库,不然会报错的哟!!!

对于上述索引范围的判断,介绍一种简单的办法,此种办法,使用的时一个数取于所获的元素的length值,不管如何,他的范围只是会0~a.length之间

num = (num + 1) % count;

ok,很方便的使用jQuery实现了轮播图效果,欢迎您提出宝贵的意见!!!

jQuey实现轮播图效果的更多相关文章

  1. js实现轮播图效果(附源码)--原生js的应用

    1.js实现轮播图效果 <!DOCTYPE html><html lang="en"><head> <meta charset=" ...

  2. 用html +js+css 实现页面轮播图效果

    html 页面 <html lang="en"> <head> <meta charset="UTF-8"> <met ...

  3. JavaScript实现轮播图效果

    我又来了,同志们.老想你们了 捕获小可爱一枚. 下面进入正题:用JavaScript原生代码写轮播图效果. 具体效果就不多说了,网站上面的轮播效果我们都知晓.下面是展示代码 html代码: <d ...

  4. 小程序实践(二):swiper组件实现轮播图效果

    swiper组件类似于Android中的ViewPager,实现类似轮播图的效果,相对于Android的Viewpager,swiper实现起来更加方便,快捷. 效果图: 首先看下swiper支持的属 ...

  5. Android项目实战(四十七):轮播图效果Viewpager

    简易.常用的轮播图效果ViewPager ,老技术了,记一笔留着以后ctrl C + ctrl V    需求如下: 不定张个数的ImagView轮播,右下角显示轮播点图标,每隔固定时间切换下一张,最 ...

  6. 纯CSS实现轮播图效果,你不知道的CSS3黑科技

    前言 轮播图已经是一个很常见的东西,尤其是在各大App的首页顶部栏,经常会轮番显示不同的图片. 一提到轮播图如何实现时,很多人的第一反应就是使用Javascript的定时器,当然这种方法是可以实现的. ...

  7. js原生实现轮播图效果(面向对象编程)

    面向对象编程js原生实现轮播图效果 1.先看效果图 2.需要实现的功能: 自动轮播 点击左右箭头按钮无缝轮播 点击数字按钮切换图片 分析:如何实现无缝轮播? 在一个固定大小的相框里有一个ul标签,其长 ...

  8. 高仿阴阳师官网轮播图效果的jQuery插件

    代码地址如下:http://www.demodashi.com/demo/12302.html 插件介绍 这是一个根据阴阳师官网的轮播效果所扒下来的轮播插件,主要应用于定制个性化场景,目前源码完全公开 ...

  9. js 实现淘宝无缝轮播图效果,可更改配置参数 带完整版解析代码[slider.js]

    前言:         本人纯小白一个,有很多地方理解的没有各位大牛那么透彻,如有错误,请各位大牛指出斧正!小弟感激不尽.         本篇文章为您分析一下原生JS写淘宝无缝轮播图效果 需求分析: ...

随机推荐

  1. OpenStack 学习笔记 (三)

    个人网站:臭蛋www.choudan.net 一直苦于不知道如何加入到开源社区参与开发,感受开源社区分布式协作开发和巨神们coding的魅力,特意在网上查了资料,直接指导的很少,还得的靠官网上的文档. ...

  2. php 空格无法替换,utf-8空格惹的祸

    一次坑爹的小bug.读取一段文字(编码utf-8),想替换掉空格,str_replace(" "..).preg_replace("/\s/"..)都不起作用. ...

  3. spring事务的理解

    特性 一致性:业务处理要么都成功,要么都失败,不能部分成功不分失败 原子性:业务操作是由多个动作完成,这些动作不可分割,要么都执行,要么都不执行 隔离性:事务间之间要做隔离,不要互相影响 持久性:操作 ...

  4. 初始python(三)

    1. 循环 if, while, forbreak : 结束整个循环continue :跳出当前这次循环,但不结束整个循环else :结束整个循环后才执行,不能与break合用,但可以与continu ...

  5. Apache,php配置

    很多朋友想要在window下配置apache+php+mysql运行环境,其实从这么长时间的经验来看,win2003下还是用iis,如果为了学习或对apache特别熟悉的朋友可以用apache   一 ...

  6. 020.1.2 Arrays集合工具类

    内容:一些关于集合常用方法 在Java.util包里面,可以自己测试一下1.查找2.复制数组3.复制数组指定范围4.排序5.返回hash值6.数组转换成String7.数组转换成集合 Arrays.a ...

  7. Java集合源码 -- Collection框架概述

    1.概述 collection框架是用于处理各种数据结构的,要根据各种数据结构的特点理解它 它能够保存对象,并提供很多的操作去管理对象,当你面临下面的情况时,也许你应该考虑用集合类 1.容器的长度是不 ...

  8. C/C++——赋值理解(匿名临时对象)

    对三,王炸: 赋值的本质,是将变量传递给一个匿名临时变量,之后再传递给另一个变量.  匿名临时对象: #include <iostream> using namespace std; cl ...

  9. 【Vue】hello world

    参考链接:http://www.jianshu.com/p/5ba253651c3b 1.Vue 是一个前端框架,特点是数据绑定.组件化 如果你之前已经习惯了用jQuery操作DOM,学习Vue.js ...

  10. 【node】安装

    参考链接: http://www.runoob.com/nodejs/nodejs-install-setup.html http://blog.csdn.net/u010255310/article ...