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写淘宝无缝轮播图效果 需求分析: ...
随机推荐
- Python问题1:IndentationError:expected an indented block
Python语言是一款对缩进非常敏感的语言,给很多初学者带来了困惑,即便是很有经验的python程序员,也可能陷入陷阱当中.最常见的情况是tab和空格的混用会导致错误,或者缩进不对,而这是用肉眼无法分 ...
- 伪数组 arguments
arguments代表的是实参.有个讲究的地方是:arguments只在函数中使用. (1)返回函数实参的个数:arguments.length 例子: fn(2,4); fn(2,4,6); fn( ...
- [翻译] JTNumberScrollAnimatedView
JTNumberScrollAnimatedView 本人视频教程系类 iOS中CALayer的使用 效果: Use JTNumberScrollAnimatedView for have a n ...
- 绘制虚线的UIView
绘制虚线的UIView CAShapeLayer配合贝塞尔曲线可以绘制曲线,笔者继承了一个UIView的子类,并将该子类的backedLayer替换为CAShapeLayer,以此来实现绘制虚线的效果 ...
- December 10th 2016 Week 50th Saturday
Storms make trees take deeper roots. 风暴使树木深深扎根. Sometimes, you may feel frustrated for failing to wi ...
- linux c编程调用系统的动态库时,要使用dlopen等函数吗?
同问 linux c编程调用系统的动态库时,要使用dlopen等函数吗? 2012-11-27 21:55 提问者: hnwlxyzhl 我来帮他解答 满意回答 2012-12-07 09:08 li ...
- 关于$.fn.scrollPath is not a function
关于$.fn.scrollPath is not a function 在做项目过程中,用到了一个jQuery的滚动路径插件——jQuery Scroll Path.引入相关的js文件后,但是控制台一 ...
- IntelliJ IDEA 与Eclipse Link with Editor等价功能设置
Link With Editor是Eclipse内置功能中十分小巧,但却异常实用的一个功能. 这个开关按钮 (Toggle Button) 出现在各式导航器视图 ( 例如 Resource Explo ...
- 以整数元素构成的list中的数字组成最小整数
问题 把一个int型数组中的数字拼成一个串,这个串代表的数字最小. 思路说明 不同角度,对原题理解有所不同.我依照以下的理解方式求解. 对这个问题的理解: 有一个元素是int类型的list: 将上述l ...
- 2018-2019-2 网络对抗技术 20165322 Exp3 免杀原理与实践
2018-2019-2 网络对抗技术 20165322 Exp3 免杀原理与实践 目录 实验内容与步骤 正确使用msf编码器,msfvenom生成如jar之类的其他文件,veil-evasion,加壳 ...