jQuey实现轮播图效果
再平常的浏览器页面,轮播图都是必不可缺少的一个板块,在这总结了一下轮播图基本的一些样式
首先介绍一下,本文实现的轮播图的基本效果:
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"><</p>
<p class="nextImg">></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实现轮播图效果的更多相关文章
- js实现轮播图效果(附源码)--原生js的应用
1.js实现轮播图效果 <!DOCTYPE html><html lang="en"><head> <meta charset=" ...
- 用html +js+css 实现页面轮播图效果
html 页面 <html lang="en"> <head> <meta charset="UTF-8"> <met ...
- JavaScript实现轮播图效果
我又来了,同志们.老想你们了 捕获小可爱一枚. 下面进入正题:用JavaScript原生代码写轮播图效果. 具体效果就不多说了,网站上面的轮播效果我们都知晓.下面是展示代码 html代码: <d ...
- 小程序实践(二):swiper组件实现轮播图效果
swiper组件类似于Android中的ViewPager,实现类似轮播图的效果,相对于Android的Viewpager,swiper实现起来更加方便,快捷. 效果图: 首先看下swiper支持的属 ...
- Android项目实战(四十七):轮播图效果Viewpager
简易.常用的轮播图效果ViewPager ,老技术了,记一笔留着以后ctrl C + ctrl V 需求如下: 不定张个数的ImagView轮播,右下角显示轮播点图标,每隔固定时间切换下一张,最 ...
- 纯CSS实现轮播图效果,你不知道的CSS3黑科技
前言 轮播图已经是一个很常见的东西,尤其是在各大App的首页顶部栏,经常会轮番显示不同的图片. 一提到轮播图如何实现时,很多人的第一反应就是使用Javascript的定时器,当然这种方法是可以实现的. ...
- js原生实现轮播图效果(面向对象编程)
面向对象编程js原生实现轮播图效果 1.先看效果图 2.需要实现的功能: 自动轮播 点击左右箭头按钮无缝轮播 点击数字按钮切换图片 分析:如何实现无缝轮播? 在一个固定大小的相框里有一个ul标签,其长 ...
- 高仿阴阳师官网轮播图效果的jQuery插件
代码地址如下:http://www.demodashi.com/demo/12302.html 插件介绍 这是一个根据阴阳师官网的轮播效果所扒下来的轮播插件,主要应用于定制个性化场景,目前源码完全公开 ...
- js 实现淘宝无缝轮播图效果,可更改配置参数 带完整版解析代码[slider.js]
前言: 本人纯小白一个,有很多地方理解的没有各位大牛那么透彻,如有错误,请各位大牛指出斧正!小弟感激不尽. 本篇文章为您分析一下原生JS写淘宝无缝轮播图效果 需求分析: ...
随机推荐
- Java快速入门-02-基础篇
Java快速入门-02-基础篇 上一篇应该已经让0基础的人对 Java 有了一些了解,接一篇更进一步 使用 Eclipse 快捷键 这个老师一般都经常提,但是自己不容易记住,慢慢熟练 快捷键 快捷键作 ...
- C语言中关键词static的用法与作用域
一.面向过程设计中的static 转载:http://blog.csdn.net/celerylxq/article/details/6160499 1.静态全局变量 在全局变量前,加上关键字stat ...
- MVC实例分析1.1
E_S源码百度云分享链接: http://pan.baidu.com/s/1dFHzEJv 思维导图源文件分享链接: http://pan.baidu.com/s/1hrAXGC8 简单PPT分享链接 ...
- join语句中on条件与where条件的区别
大纲:on是在生成连接表的起作用,where是生成连接表之后对连接表再进行过滤 当使用left join时,无论on的条件是否满足,都会返回左表的所有记录,对于满足的条件的记录,两个表对应的记录会连接 ...
- Java学习---程序设计_面试题[2]
百度2017春招笔试真题编程题集合之买帽子 // 2017-10-09 // 题目描述 // 度度熊想去商场买一顶帽子,商场里有N顶帽子,有些帽子的价格可能相同.度度熊想买一顶价格第三便宜的帽子,问第 ...
- 乘风破浪:LeetCode真题_020_Valid Parentheses
乘风破浪:LeetCode真题_020_Valid Parentheses 一.前言 下面开始堆栈方面的问题了,堆栈的操作基本上有压栈,出栈,判断栈空等等,虽然很简单,但是非常有意义. 二.Valid ...
- windows下的FTP命令
假设要连接的FTP信息如下: FTP Server: FtpTest User: tester Password: 123123 打开Windows的开始菜单,执行"运行"命令,在 ...
- IOS 对JSON解析的要求
JOSN格式的原始字符串中, 键名必须为 引号 “” 包含的字符串,值必须是数组("[]" 用中括号包起来的部分),字典("{}" 用中括号包起来的部分),数字 ...
- jQueryeasyUI+Hibernate+struts2实现商城后台管理之添加操作时的unique验证
1. 在admin.js中添加扩展验证的操作checkName var checkUrl = "./hytc/AdminAction_check.action";
- AngularJs 与服务器通信 $http, $q, $resource
$http服务是AngularJS系统自带的,可以用来进行网络通信.获取远程服务器的数据.要记住的是,$http是对浏览器XMLHttpRequest的封装,也就是说,它其实是Ajax. $http( ...