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

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

  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. volley2--volley的使用和架构

    图片: 下面只是笼统的介绍,大家可以对比自己的想法,看看自己是不是有什么考虑不周的(如果是你实现这样一个框架的话) 1,Request的设计,我们在得到response之后,我们可能根据项目需求希望有 ...

  2. 如何用kindle看论文

    kindle的pdf显示效果向来不好,那么如何把pdf转换成mobi格式呢 可以把个人文件(pdf)发送至您的[发送至Kindle]电子邮箱时,在电子邮件的主题栏中填写"convert&qu ...

  3. 利用Vagrant完成开发环境配置

    作者:astaxie链接:https://github.com/astaxie/go-best-practice/blob/master/ebook/zh/01.0.md著作权归作者所有.商业转载请联 ...

  4. Android自定义View之绘制虚线

    现在实现一个效果,有个虚线分割和阴影效果.一个一个实现. 分为2中方式. 1.设计出图,我们SRC引入进来(最简单,但是需要其他资源支持). 2.code实现,有些难度,需要查资料. 现在把第2种方式 ...

  5. postman trigger xdebug session in phpstorm

    phpstorm是一款非常棒的php开发调试工具,一般情况下我们使用firefox/chrome的bookmark,开启phpstorm debug侦听,随后点击start debugger, 我们就 ...

  6. 创建基于 AFS 的 Docker 容器卷

    标准的 Docker 容器卷一般是位于 Docker 主机上的一个本地目录.在这样的配置下,容器必须依赖于一台特定的主机,因此使得容器的迁移和扩展变得困难.通过使用容器卷插件,能让容器访问独立于主机的 ...

  7. Windows Azure系列公开课 - 第二课:为什么选择Windows Azure(上)

    Windows Azure是微软的云平台,可以提供广泛服务.您可以通过它搭建.部署并管理解决方案,用于实现您可以想象的几乎任何目标.换言之,WindowsAzure是拥有无限可能的世界.无论您是需要运 ...

  8. leetcode BFS

    1. word ladder class Solution { public: int ladderLength(string beginWord, string endWord, unordered ...

  9. Mac OS 10.8 配置SVN服务器

    Mac 10.8开始,不再默认安装svn,需要自行安装 如果您安装了XCode,会随同安装svn 更省事的办法: 1.安装homebrew,看看官网 http://brew.sh/index_zh-c ...

  10. ZT fcntl设置FD_CLOEXEC标志作用

    fcntl设置FD_CLOEXEC标志作用 分类: C/C++ linux 2011-11-02 22:11 3217人阅读 评论(0) 收藏 举报 bufferexegccnullfile 通过fc ...